private Favour GetFavourByModel(FavourModel model) { return(new Favour { Id = model.Id, Name = model.Name, Cost = model.Cost }); }
public async Task <IActionResult> CreateFavour(FavourModel model) { if (ModelState.IsValid) { var favour = await _favourService.GetFavourByName(model.Name); if (favour == null) { await _favourService.CreateFavourWithFavourModel(model); return(RedirectToAction("GetFavours", "Manager")); } ModelState.AddModelError("GlobalError", "Такая услуга уже существует"); } return(View(model)); }
public async Task <IActionResult> EditFavour(FavourModel model) { if (ModelState.IsValid) { var favour = await _favourService.GetFavourById(model.Id); var possible_favour = await _favourService.GetFavourByName(model.Name); if (favour.Name == model.Name || possible_favour == null) { await _favourService.UpdateFavourWithFavourModel(model); return(RedirectToAction("GetFavours", "Manager")); } ModelState.AddModelError("GlobalError", "Такая услуга уже существует."); } return(View("GetFavour", model)); }
public async Task UpdateFavourWithFavourModel(FavourModel model) { var favour = GetFavourByModel(model); await _favourRepository.Update(favour); }