public async Task <IActionResult> Index()
        {
            var listOperation = await _bo.ListNonDeletedAsync();

            if (!listOperation.Success)
            {
                return(View("Error", new ErrorViewModel()
                {
                    RequestId = listOperation.Exception.Message
                }));
            }
            var mIds = listOperation.Result.Select(x => x.MenuId).Distinct().ToList();
            var cIds = listOperation.Result.Select(x => x.CourseId).Distinct().ToList();
            var dIds = listOperation.Result.Select(x => x.DishId).Distinct().ToList();


            var lst = new List <ServingViewModel>();

            foreach (var item in listOperation.Result)
            {
                lst.Add(ServingViewModel.Parse(item));
            }
            ViewData["Title"]       = "Servings";
            ViewData["Breadcrumbs"] = GetCrumbs();
            ViewData["Menus"]       = await GetMenuViewModels(mIds);

            ViewData["Courses"] = await GetCourseViewModels(cIds);

            ViewData["Dishes"] = await GetDishViewModels(dIds);

            return(View(lst));
        }
        public ActionResult <List <ServingViewModel> > List()
        {
            var res = _bo.List();

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

            foreach (var item in res.Result)
            {
                list.Add(ServingViewModel.Parse(item));
            }
            return(list);
        }
        public ActionResult <ServingViewModel> Get(Guid id)
        {
            var res = _bo.Read(id);

            if (res.Success)
            {
                if (res.Result == null)
                {
                    return(NotFound());
                }
                var svm = ServingViewModel.Parse(res.Result);
                return(svm);
            }
            else
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
        public async Task <IActionResult> GetAsync(Guid id)
        {
            var getResult = await _bo.ReadAsync(id);

            if (!getResult.Success)
            {
                return(InternalServerError(getResult.Exception));
            }
            var item = getResult.Result;

            if (item == null)
            {
                return(NotFound());
            }
            var vm = ServingViewModel.Parse(item);

            return(Ok(vm));
        }
        public async Task <IActionResult> ListAsync()
        {
            var listResult = await _bo.ListNonDeletedAsync();

            if (!listResult.Success)
            {
                return(InternalServerError(listResult.Exception));
            }
            var list = listResult.Result;
            var lst  = new List <ServingViewModel>();

            foreach (var item in list)
            {
                var vm = ServingViewModel.Parse(item);
                lst.Add(vm);
            }
            return(Ok(lst));
        }
        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", getOperation.Exception.Message));
            }
            if (getOperation.Result == null)
            {
                return(NotFound());
            }
            var vm = ServingViewModel.Parse(getOperation.Result);

            ViewData["Header"] = "Serving";
            return(View(vm));
        }
        public async Task <IActionResult> Edit(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 = ServingViewModel.Parse(getOperation.Result);

            return(View(vm));
        }