示例#1
0
        public async Task <ActionResult> Edit(int id, PolyclinicModel model)
        {
            if (ModelState.IsValid && model != null)
            {
                var data = Mapper.Map <PolyclinicModel, Polyclinic>(model);
                await _polyclinicService.UpdateAsync(data, id);

                return(RedirectToAction("Index"));
            }

            return(View());
        }
示例#2
0
        public async Task <ActionResult> Create(PolyclinicModel model)
        {
            if (ModelState.IsValid)
            {
                var data = Mapper.Map <PolyclinicModel, Polyclinic>(model);

                if (_polyclinicService.GetAll().FirstOrDefault(s => s.Name.ToLower() == model.Name?.ToLower()) == null)
                {
                    if (!ModelState.IsValid)
                    {
                        return(View(model));
                    }

                    await _polyclinicService.AddAsync(data);

                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError("Name", "Такой магазин уже зарегистрирован. Пожалуйста, введите другое наименование!");
            }
            return(View(model));
        }