public async Task <IActionResult> Details(Guid?id) { if (id == null) { return(NotFound()); } var getOperation = await _fbo.ReadAsync((Guid)id); if (!getOperation.Success) { return(View("Error", new ErrorViewModel() { RequestId = getOperation.Exception.Message })); } if (getOperation.Result == null) { return(NotFound()); } var catOperation = await _cbo.ReadAsync(getOperation.Result.CategoryId); var fvm = FoodViewModel.Parse(getOperation.Result); fvm.Fats = Math.Round(fvm.Fats, 2); fvm.Carbohydrates = Math.Round(fvm.Carbohydrates, 2); fvm.Protein = Math.Round(fvm.Protein, 2); fvm.Alcohol = Math.Round(fvm.Alcohol, 2); fvm.Calories = Math.Round(fvm.Calories, 2); var cvm = CategoryViewModel.Parse(catOperation.Result); var dic = new Dictionary <FoodViewModel, CategoryViewModel>(); dic.Add(fvm, cvm); return(View(dic)); }
public async Task <IActionResult> Details(Guid timeofday, string date) { var dateResult = DateTime.Parse(date); var dlistOperation = await _bo.FilterAsync(x => DetailFilter(timeofday, dateResult, x)); 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 todReadOperation = await _todbo.ReadAsync(timeofday); if (!todReadOperation.Success) { return(View("Error", new ErrorViewModel() { RequestId = todReadOperation.Exception.Message })); } ViewBag.TimeOfDay = todReadOperation.Result; ViewBag.Day = dateResult; return(View(lst)); }
private async Task <List <FoodViewModel> > GetFoodViewModels(List <Guid> ids) { var filterOperation = await _fbo.FilterAsync(x => ids.Contains(x.Id)); var fList = new List <FoodViewModel>(); foreach (var item in filterOperation.Result) { fList.Add(FoodViewModel.Parse(item)); } return(fList); }
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)); }
public ActionResult <List <FoodViewModel> > List() { var res = _bo.List(); if (!res.Success) { StatusCode((int)HttpStatusCode.InternalServerError); } var list = new List <FoodViewModel>(); foreach (var item in res.Result) { list.Add(FoodViewModel.Parse(item)); } return(list); }
public ActionResult <FoodViewModel> Get(Guid id) { var res = _bo.Read(id); if (res.Success) { if (res.Result == null) { return(NotFound()); } var fvm = FoodViewModel.Parse(res.Result); return(fvm); } else { return(StatusCode((int)HttpStatusCode.InternalServerError)); }; }
public async Task <IActionResult> Edit(Guid?id) { if (id == null) { return(NotFound()); } var getOperation = await _fbo.ReadAsync((Guid)id); if (!getOperation.Success) { return(View("Error", new ErrorViewModel() { RequestId = getOperation.Exception.Message })); } if (getOperation.Result == null) { return(NotFound()); } var fvm = FoodViewModel.Parse(getOperation.Result); var listOperation = await _cbo.ListAsync(); if (!listOperation.Success) { return(View("Error", new ErrorViewModel() { RequestId = listOperation.Exception.Message })); } var cats = new List <SelectListItem>(); foreach (var item in listOperation.Result) { cats.Add(new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }); } ViewBag.Categories = cats; return(View(fvm)); }
public async Task <IActionResult> Index() { Func <Foods, bool> condition; if (!User.Identity.IsAuthenticated) { condition = x => x.IsGlobal == true && x.IsDeleted == false; } else { var userId = (await _uManager.FindByNameAsync(User.Identity.Name)).ProfileId; condition = x => x.IsDeleted == false && (x.IsGlobal == true || x.ProfileId == userId); } var listOperation = await _fbo.FilterAsync(condition); //var listOperation = await _fbo.ListAsync(); if (!listOperation.Success) { return(View("Error", new ErrorViewModel() { RequestId = listOperation.Exception.Message })); } var dic = new Dictionary <FoodViewModel, string>(); foreach (var item in listOperation.Result) { item.Fats = Math.Round(item.Fats, 2); item.Carbohydrates = Math.Round(item.Carbohydrates, 2); item.Protein = Math.Round(item.Protein, 2); item.Alcohol = Math.Round(item.Alcohol, 2); item.Calories = Math.Round(item.Calories, 2); var cat = await _cbo.ReadAsync(item.CategoryId); var catName = cat.Result.Name; dic.Add(FoodViewModel.Parse(item), catName); } return(View(dic)); }
private async Task <FoodViewModel> GetFoodViewModel(Guid id) { var getOperation = await _fbo.ReadAsync(id); return(FoodViewModel.Parse(getOperation.Result)); }
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)); }