Esempio n. 1
0
        public ActionResult MainTable(string code, DateTime?date)
        {
            var model = new ReservationView();

            try
            {
                model.Date = date ?? DateTime.Now.Date;

                using (IUnitOfWork uow = new UnitOfWork(new DbContextWrap()))
                {
                    if (tables == null)
                    {
                        tables = repository.GetAll <TableModel>(uow).ToList();
                    }
                    model.Tables = tables;
                    if (times == null)
                    {
                        times = timeManager.GetTimesForDayOfTheWeek(uow, model.Date);
                        if (!times.Any())
                        {
                            times     = repository.GetAll <TimeModel>(uow).ToList();
                            model.Day = new DayReservation(true);
                        }
                    }
                    model.Times = times;

                    model.IsPicked = reservationManager.GetPickedForDateAndUser(uow, model.Date, User.Identity.GetUserId()).Any();
                    if (!model.Day.IsCancelled)
                    {
                        model.Day = reservationManager.GetReservationsForDate(uow, model.Date, tables, User.Identity.GetUserId());
                    }
                }

                model.ReturnCode = ReturnCode.FromString(code) ?? new ReturnCode(ReturnCodeLevel.RELOAD, Resource.ReloadOK, null);

                ModelState.Clear();
            }
            catch (Exception ex)
            {
                model.ReturnCode.Error(ex.Message);
                logger.Error(ex.Message);
            }

            return(View(model));
        }