public async Task <IActionResult> Create(MenuViewModel vm) { 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; if (ModelState.IsValid) { var model = vm.ToModel(); var createOperation = await _bo.CreateAsync(model); if (!createOperation.Success) { TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, createOperation.Exception); return(View(vm)); } else { return(OperationSuccess("The record was successfuly created")); } } return(View(vm)); }
public async Task <IActionResult> CreateAsync([FromBody] MenuViewModel vm) { var newItem = vm.ToModel(); var result = await _bo.CreateAsync(newItem); if (!result.Success) { return(InternalServerError(result.Exception)); } return(Created(Request.Path.Value, null)); }
public void TestCreateAndListMenuAsync() { RestaurantSeeder.Seed(); var mbo = new MealBusinessObject(); var rbo = new RestaurantBusinessObject(); var mebo = new MenuBusinessObject(); var m = mbo.ListAsync().Result.Result.First(); var r = rbo.ListAsync().Result.Result.First(); var dr = new Menu(DateTime.Now, r.Id, m.Id); var resCreate = mebo.CreateAsync(dr).Result; var resGet = mebo.ReadAsync(dr.Id).Result; Assert.IsTrue(resCreate.Success && resGet.Success && resGet.Result != null); }
public void TestCreateMenuAsync() { ContextSeeders.Seed(); var mbo = new MenuBusinessObject(); var rbo = new RestaurantBusinessObject(); var mealbo = new MealBusinessObject(); var restaurant = new Restaurant("a", "b", "c", "d", "f", 6); var meal = new Meal("a", "b", "c"); rbo.Create(restaurant); mealbo.Create(meal); var menu = new Menu(DateTime.Now, restaurant.Id, meal.Id); var resCreate = mbo.CreateAsync(menu).Result; var resGet = mbo.ReadAsync(menu.Id).Result; Assert.IsTrue(resCreate.Success && resGet.Success && resGet.Result != null); }