Beispiel #1
0
        public IActionResult Edit(SpecificationCreateOrUpdateModel model, bool continueEditing)
        {
            var error = false;

            if (ModelState.IsValid)
            {
                // get model from session
                var sessionModel = JsonConvert.DeserializeObject <ManufacturerCreateOrUpdateModel>(Session.GetString(_sessionKey));
                model.Id        = sessionModel.Id;
                model.DateAdded = sessionModel.DateAdded;

                // check if user edit the name
                if (model.Name.ToLower() != sessionModel.Name.ToLower())
                {
                    // check if name exist
                    if (_dataHelper.CheckForDuplicate(ServiceType.Specification, DataType.Name, model.Name))
                    {
                        ModelState.AddModelError(string.Empty, "Specification name already exist");
                        error = true;
                    }
                }

                // if everything works
                if (!error)
                {
                    // map model to entity
                    var specificationEntity = _mapper.Map <SpecificationCreateOrUpdateModel, Specification>(model);
                    specificationEntity.DateModified = DateTime.Now;

                    // save
                    _specificationService.UpdateSpecification(specificationEntity);

                    if (continueEditing)
                    {
                        return(RedirectToAction("Edit", new { id = specificationEntity.Id, ActiveTab = model.ActiveTab }));
                    }

                    return(RedirectToAction("List"));
                }
            }

            return(View(model));
        }