コード例 #1
0
        public ActionResult Index()
        {
            HomeViewModel model = new HomeViewModel();

            try
            {
                model.ChoiceHistory = _choiceService.GetTodayChoiceHistory();
                model.Vote          = _voteService.GetTodayVote(User.Identity.Name);
                model.ScoreBoard    = _voteService.GetAllTodayVotesGroupByRestaurant();
                model.SetListToJson();

                if (NotificationScheduler.TriggerAlreadySchedule())
                {
                    model.SetTimeInteval(NotificationScheduler.hour, NotificationScheduler.minute);
                }

                if (model.ChoiceHistory != null)
                {
                    string message = model.ChoiceHistory.Draw ? CommonMessages.VoteFinishWithDraw : CommonMessages.VoteFinish;
                    throw new Exception(string.Format(message, model.ChoiceHistory.Restaurant.Name));
                }

                if (model.ChoiceHistory != null || model.Vote != null)
                {
                    throw new Exception(string.Format(CommonMessages.YouAlreadyVoteToday, model.Vote.Restaurant.Name));
                }

                model.TitleMessage = CommonMessages.ChooseYourFavorite;
                model.Restaurants  = _restaurantService.GetWeekAvaiable();
            }
            catch (Exception ex)
            {
                model.TitleMessage = ex.Message;
            }

            return(View(model));
        }