public DbResponse <SpecificationModel> Add(SpecificationAddModel model, string userName) { try { var registrationId = _db.Registration.GetRegID_ByUserName(userName); if (registrationId == 0) { return(new DbResponse <SpecificationModel>(false, "Invalid User")); } model.CreatedByRegistrationId = registrationId; if (string.IsNullOrEmpty(model.KeyName)) { return(new DbResponse <SpecificationModel>(false, "Invalid Data")); } if (_db.Specification.IsExistName(model.KeyName)) { return(new DbResponse <SpecificationModel>(false, "Specification Name already Exist", null, "Name")); } _db.Specification.Add(model); _db.SaveChanges(); var data = _mapper.Map <SpecificationModel>(_db.Specification.Specification); return(new DbResponse <SpecificationModel>(true, "Success", data)); } catch (Exception e) { return(new DbResponse <SpecificationModel>(false, e.Message)); } }
public IActionResult Add(SpecificationAddModel model) { var response = _specification.Add(model, User.Identity.Name); return(Json(response)); }