Exemplo n.º 1
0
        private async Task <List <TimeOfDayViewModel> > GetTimeOfDayViewModels()
        {
            var filterOperation = await _todbo.ListAsync();

            var todList = new List <TimeOfDayViewModel>();

            foreach (var item in filterOperation.Result)
            {
                todList.Add(TimeOfDayViewModel.Parse(item));
            }
            return(todList);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var getOperation = await _bo.ReadAsync((Guid)id);

            if (!getOperation.Success)
            {
                return(View("Error", new ErrorViewModel()
                {
                    RequestId = getOperation.Exception.Message
                }));
            }
            if (getOperation.Result == null)
            {
                return(NotFound());
            }
            var vm = MealViewModel.Parse(getOperation.Result);

            var getFOperation = await _fbo.ReadAsync(getOperation.Result.FoodId);

            if (!getFOperation.Success)
            {
                return(View("Error", new ErrorViewModel()
                {
                    RequestId = getFOperation.Exception.Message
                }));
            }
            if (getFOperation.Result == null)
            {
                return(NotFound());
            }

            var getTodOperation = await _todbo.ReadAsync(getOperation.Result.TimeOfDayId);

            if (!getTodOperation.Success)
            {
                return(View("Error", new ErrorViewModel()
                {
                    RequestId = getTodOperation.Exception.Message
                }));
            }
            if (getTodOperation.Result == null)
            {
                return(NotFound());
            }

            ViewData["Food"]      = FoodViewModel.Parse(getFOperation.Result);
            ViewData["TimeOfDay"] = TimeOfDayViewModel.Parse(getTodOperation.Result);
            return(View(vm));
        }
Exemplo n.º 3
0
        public ActionResult <List <TimeOfDayViewModel> > List()
        {
            var res = _bo.List();

            if (!res.Success)
            {
                StatusCode((int)HttpStatusCode.InternalServerError);
            }
            var list = new List <TimeOfDayViewModel>();

            foreach (var item in res.Result)
            {
                list.Add(TimeOfDayViewModel.Parse(item));
            }

            return(list);
        }
Exemplo n.º 4
0
        public ActionResult <TimeOfDayViewModel> Get(Guid id)
        {
            var res = _bo.Read(id);

            if (res.Success)
            {
                if (res.Result == null)
                {
                    return(NotFound());
                }
                var todvm = TimeOfDayViewModel.Parse(res.Result);

                return(todvm);
            }
            else
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Index()
        {
            var listOperation = await _bo.ListAsync();

            if (!listOperation.Success)
            {
                return(View("Error", new ErrorViewModel()
                {
                    RequestId = listOperation.Exception.Message
                }));
            }
            var list = new List <TimeOfDayViewModel>();

            foreach (var item in listOperation.Result)
            {
                list.Add(TimeOfDayViewModel.Parse(item));
            }
            return(View(list));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var getOperation = await _bo.ReadAsync((Guid)id);

            if (!getOperation.Success)
            {
                return(View("Error", new ErrorViewModel()
                {
                    RequestId = getOperation.Exception.Message
                }));
            }
            if (getOperation.Result == null)
            {
                return(NotFound());
            }
            var vm = TimeOfDayViewModel.Parse(getOperation.Result);

            return(View(vm));
        }
Exemplo n.º 7
0
        private async Task <TimeOfDayViewModel> GetTimeOfDayViewModel(Guid id)
        {
            var getOperation = await _todbo.ReadAsync(id);

            return(TimeOfDayViewModel.Parse(getOperation.Result));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Index(int?week = 0)
        {
            //var fIds = listOperation.Result.Select(x => x.FoodId).Distinct().ToList();
            //var todIds = listOperation.Result.Select(x => x.TimeOfDayId).Distinct().ToList();

            DateTime today            = DateTime.Today;
            int      currentDayOfWeek = (int)today.DayOfWeek;
            DateTime sunday           = today.AddDays(-currentDayOfWeek);
            DateTime monday           = sunday.AddDays(1 + (double)week * 7);

            if (currentDayOfWeek == 0)
            {
                monday = monday.AddDays(-7);
            }
            var weekDays = Enumerable.Range(0, 7).Select(days => monday.AddDays(days)).ToList();

            ViewBag.WeekDay = weekDays;

            var dlistOperation = await _bo.FilterAsync(x => x.ProfileId == new Guid("00000000-0000-0000-0000-000000000001") && x.Day >= weekDays[0] && x.Day <= weekDays[6] && x.IsDeleted == false);

            if (!dlistOperation.Success)
            {
                return(View("Error", new ErrorViewModel()
                {
                    RequestId = dlistOperation.Exception.Message
                }));
            }

            var lst = new List <MealViewModel>();

            foreach (var item in dlistOperation.Result)
            {
                lst.Add(MealViewModel.Parse(item));
            }

            var flistOperation = await _fbo.ListAsync();

            if (!flistOperation.Success)
            {
                return(View("Error", new ErrorViewModel()
                {
                    RequestId = flistOperation.Exception.Message
                }));
            }
            var foods = new List <FoodViewModel>();

            foreach (var item in flistOperation.Result)
            {
                foods.Add(FoodViewModel.Parse(item));
            }
            ViewBag.Foods = foods;

            var todlistOperation = await _todbo.ListAsync();

            if (!todlistOperation.Success)
            {
                return(View("Error", new ErrorViewModel()
                {
                    RequestId = todlistOperation.Exception.Message
                }));
            }
            var tods = new List <TimeOfDayViewModel>();

            foreach (var item in todlistOperation.Result)
            {
                tods.Add(TimeOfDayViewModel.Parse(item));
            }
            ViewBag.TimesOfDay = tods.ToList();

            ViewData["week"] = week;
            return(View(lst));
        }