Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Expecting the right approach and direction for my task:

I am developing one application using MVC4.0 in front end and SQL is backend with C# code. This application is like display the list of books in the grid view. The Grid view columns like [S.No, Book Name, Reserved By, End date] etc... Once user login the application he/she can able to visible the list of all books. If any book is already reserved by some one, at that time the reserved person name displays in the 'Reserved By' Column of that corresponding row. The user can able to reserve only 7 days, after 7 days expired the corresponding book will automatically get released and any other user can able to reserve the same book.
In this scenario, I have completed all those things expect the auto reserve. I decide to implement in this scenario to match the 'End Date' in the Column and System current date. If End date is less than System Current date it will get automatically release. So I would like to all give me the suggestions in which approach I can start.

I guess the few of Challenges in this:
1.The device will get release exactly end of the End Date.
(In this I am confusing using timer or Business Logic to achieve this scenario)

2.If the none of the user login the application in that case also need to release the book once End date got expired.
(I hope if I go with Business Logic this will not work out)

3.End date should compare with Server time not in local host time. Because user could change the local system time.

(If any more challenges points I forget to post here I will update later. Apart from that if you feel any of the challenges in this scenario please let me know)

I can understand I am little confuse your understanding of my task scenario. Sorry for advance :)

The most of the part I have completed in this project but the Automatic Release option only for pending in my task. So please help me to move forward.

Advance thanks who read this top to bottom..........
Posted
Updated 6-Dec-14 21:39pm
v3
Comments
Kornfeld Eliyahu Peter 7-Dec-14 3:10am    
http://mattgemmell.com/what-have-you-tried/
BillWoodruff 7-Dec-14 3:12am    
When you use the word "device" here are you referring to your application/web-site, or to some kind of hardware ?
vasanthkumarmk 7-Dec-14 3:23am    
Sorry mistakenly I mentioned here as 'device' instead of 'book'..... Sorry....
BillWoodruff 7-Dec-14 4:24am    
Let me ask you:

1. the "release" of the book ... the setting of a variable that indicates it is available for check-out ... is completely independent of the fact someone may have put in some kind of order to check-out the book ... reserved it ? ... when it becomes available ?

I'm not clear on what you mean by "reserved," and if a book can be "released" if it is "reserved."

Would it be a good idea to have a variable with three possible states: in-use, available, reserved ?

1 solution

Hi,

You're using MVC so there is a server side application. If you want to do auto release system you should consider using system sheduler to perform special action on some interval. Most of hosting sites offers you that possibility.

One of solutions is to create controller with apriopriate automatic actions and call it via url.

Here you are example how to do this:
http://stackoverflow.com/questions/1987345/recommended-method-for-loading-a-url-via-a-scheduled-task-on-windows[^]

Then your controller can look like this:

C#
public class AutomatController : Controller
{
    public string ReleaseReservedBooks()
    {
        var reservedBooks = from x in db.Books
                            where x.EndDate <= DateTime.Now.AddDays(-7)
                            select x;

        foreach(var book in reservedBooks)
        {
            book.EndDate = null;
        }

        db.SaveChanges;

        return string.Format("{0} - Unreserved books: {1}", DateTime.Now, reservedBooks.Count);
    }
}


And then call URL http://yourdomain.com/Automat/ReleaseReservedBooks from scheduler.

Ofcourse you should take precautions for security reasons. For that you can make special routing (in RouteConfig.cs) leading to your controller.

[Update]
Above solutions applies to you 2nd point.
You can take similar steps while you're displaying books to logged user. Get all books, check if there are overdue reservations and remove reservations if exists:

C#
public ActionResult Index()
{
    var books = from x in db.Books
                select x;

    var changed = false;
    foreach(var book in books)
    {
        if (book.EndDate <= DateTime.Now.AddDays(-7))
        {
            book.EndDate = null;
            changed = true;
        }
    }
    if (changed)
    {
        db.SaveChanges();
    }

    return View(books);
}


I hope it help you.
 
Share this answer
 
v3
Comments
vasanthkumarmk 7-Dec-14 5:58am    
Thanks.... I will implement this code and let you know.
Marcin Kozub 7-Dec-14 11:32am    
Any particular reason why this answer was downvoted?
vasanthkumarmk 7-Dec-14 12:47pm    
Still I am in confusion, but I don't know how to explain my confusions?
Marcin Kozub 7-Dec-14 13:02pm    
So, do you have any problem with my solution? Do you have any error messages? Do you have any problem with business logic?
Try to explain step by step what you want to achieve and update your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900