public void Create_WithValidData_SavesRecordInTheDatabase() { // Arrange var newFoodItem = sut.Create(foodItem); // Assert Assert.IsNotNull(newFoodItem); Assert.IsTrue(newFoodItem.FoodId != null); // CleanUp sut.Delete(foodItem.FoodId); }
[Authorize] public async Task <IHttpActionResult> Create([FromBody] MenuItem model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { log.Info(new MDCSet(this.ControllerContext.RouteData)); await _entityRepo.Create(model); return(Ok("Registro creado exitosamente!")); } catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e); return(InternalServerError(e)); } }
public ActionResult AddMenuItem(MenuItemViewModel model) { if (ModelState.IsValid) { MenuItemRepository inventoryRepository = new MenuItemRepository(new ApplicationDbContext()); string customerId = null; var firstOrDefault = new ApplicationDbContext().Users.FirstOrDefault(cus => cus.UserName == User.Identity.Name); if (firstOrDefault != null) { customerId = firstOrDefault.Id; } model.CustomerId = customerId; model.IsActive = true; inventoryRepository.Create(model); return RedirectToAction("MenuItems"); } return View(model); }
public ActionResult AddMenuItem(MenuItemViewModel model) { if (ModelState.IsValid) { MenuItemRepository inventoryRepository = new MenuItemRepository(new ApplicationDbContext()); string customerId = null; var firstOrDefault = new ApplicationDbContext().Users.FirstOrDefault(cus => cus.UserName == User.Identity.Name); if (firstOrDefault != null) { customerId = firstOrDefault.Id; } model.CustomerId = customerId; model.IsActive = true; inventoryRepository.Create(model); return(RedirectToAction("MenuItems")); } return(View(model)); }