Esempio n. 1
0
 private Favour GetFavourByModel(FavourModel model)
 {
     return(new Favour
     {
         Id = model.Id,
         Name = model.Name,
         Cost = model.Cost
     });
 }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        public async Task UpdateFavourWithFavourModel(FavourModel model)
        {
            var favour = GetFavourByModel(model);

            await _favourRepository.Update(favour);
        }