需要正确的方法来完成我的任务 [英] Need Right Approach to achieve my task

查看:110
本文介绍了需要正确的方法来完成我的任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

期待我的任务正确的方法和方向:



我正在使用前端的MVC4.0开发一个应用程序,而SQL是使用C#代码的后端。此应用程序就像在网格视图中显示书籍列表一样。网格视图列如[S.No,Book Name,Reserved By,End date]等...一旦用户登录应用程序,他/她就可以看到所有书籍的列表。如果某人已经预订了任何书籍,那么保留的人员名称将显示在该对应行的保留者列中。用户只能保留7天,过期7天后相应的图书将自动发布,任何其他用户都可以保留同一本书。

在这种情况下,我已经完成了所有期望自动储备的事情。我决定在此方案中实施以匹配列和系统当前日期中的结束日期。如果结束日期小于系统当前日期,它将自动释放。所以我想向大家介绍一下我可以开始采取哪些方法的建议。



我想这几个挑战中的几个:

1.设备将在结束日期结束时正式发布。

(在此我使用计时器或业务逻辑来实现这种情况令人困惑)



2.如果没有用户登录在这种情况下应用程序也需要在结束日期到期后发布该书。

(我希望如果我使用Business Logic这将无法解决)



3.结束日期应与服务器时间进行比较,而不是本地主机时间。因为用户可以改变本地系统时间。



(如果有任何更多的挑战点我忘记在这里发布,我会稍后更新。除此之外,如果你觉得任何一个在这种情况下的挑战请让我知道)



我能理解我对你的任务场景的理解很少。对不起提前:)



我在这个项目中已完成的大部分内容,但仅限于我的任务中待处理的自动释放选项。所以请帮助我继续前进。



预先感谢谁从上到下阅读..........

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..........

推荐答案





您正在使用MVC,因此有一个服务器端应用程序。如果要进行自动释放系统,则应考虑使用系统sheduler在某个时间间隔内执行特殊操作。大多数托管网站都为您提供了这种可能性。



其中一个解决方案是使用apriopriate自动操作创建控制器并通过URL调用它。



这里是一个如何执行此操作的示例:

http://stackoverflow.com/questions/1987345/recommended-method-for-loading-a-url-via-a-scheduled-task-on -windows [ ^ ]



然后您的控制器可能如下所示:



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:

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);
    }
}





然后从调度程序调用URL http://yourdomain.com/Automat/ReleaseReservedBooks 。



当然,出于安全考虑,您应该采取预防措施。为此你可以通过你的控制器进行特殊的路由(在RouteConfig.cs中)。



[更新]

以上解决方案适用于你第二点。

您可以在向已登录用户显示图书时执行类似步骤。获取所有图书,检查是否有逾期预订并删除预订(如果存在):





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:

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.


这篇关于需要正确的方法来完成我的任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆