public async Task <IActionResult> New() { var listMealOperation = await _mbo.ListNonDeletedAsync(); if (!listMealOperation.Success) { return(OperationErrorBackToIndex(listMealOperation.Exception)); } var listRestOperation = await _rbo.ListNonDeletedAsync(); if (!listRestOperation.Success) { return(OperationErrorBackToIndex(listRestOperation.Exception)); } var mealList = new List <SelectListItem>(); foreach (var item in listMealOperation.Result) { mealList.Add(new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }); } var restList = new List <SelectListItem>(); foreach (var item in listRestOperation.Result) { restList.Add(new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }); } ViewBag.Meals = mealList; ViewBag.Restaurants = restList; ViewData["Title"] = "New Menu"; var crumbs = GetCrumbs(); crumbs.Add(new BreadCrumb() { Action = "New", Controller = "Menus", Icon = "fa-plus", Text = "New" }); ViewData["BreadCrumbs"] = crumbs; return(View()); }
public void TestDeleteMealAsync() { RestaurantSeeder.Seed(); var bo = new MealBusinessObject(); var resList = bo.ListAsync().Result; var total = resList.Result.Count; var resDelete = bo.DeleteAsync(resList.Result.First().Id).Result; resList = bo.ListNonDeletedAsync().Result; Assert.IsTrue(resDelete.Success && resList.Success && resList.Result.Count == total - 1); }
public void TestUpdateMealAsync() { RestaurantSeeder.Seed(); var bo = new MealBusinessObject(); var resList = bo.ListAsync().Result; var item = resList.Result.FirstOrDefault(); item.Name = "another"; var resUpdate = bo.UpdateAsync(item).Result; resList = bo.ListNonDeletedAsync().Result; Assert.IsTrue(resList.Success && resUpdate.Success && resList.Result.First().Name == "another"); }
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 <MealViewModel>(); foreach (var item in list) { var vm = MealViewModel.Parse(item); lst.Add(vm); } return(Ok(lst)); }
public async Task <IActionResult> Index() { var listOperation = await _bo.ListNonDeletedAsync(); if (!listOperation.Success) { return(OperationErrorBackToIndex(listOperation.Exception)); } var lst = new List <MealViewModel>(); foreach (var item in listOperation.Result) { lst.Add(MealViewModel.Parse(item)); } ViewData["Title"] = "Meals"; ViewData["BreadCrumbs"] = GetCrumbs(); ViewData["DeleteHref"] = GetDeleteRef(); return(View(lst)); }