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

            if (ModelState.IsValid)
            {
                // 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.DateAdded    = DateTime.Now;
                    specificationEntity.DateModified = DateTime.Now;

                    // save
                    _specificationService.InsertSpecification(specificationEntity);

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

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

            return(View(model));
        }