public IActionResult AddVehicleMake(VehicleMakeJsonModel model) { bool isAdded = false; if (!string.IsNullOrEmpty(model.Name)) { model.Name = model.Name.Trim(); isAdded = _vehicleService.AddMake(model); } string error = isAdded ? Messages.INFO_ENTITY_ADDED : Messages.ERROR_ENTITY_EXISTS; return(Json(new ResponseJsonModel(isAdded, error: error))); }
public bool AddMake(VehicleMakeJsonModel model) { var make = DbContext.VehicleMakes .SingleOrDefault(c => c.Name.ToLower() == model.Name.ToLower()); if (make == null) { make = Map(model, new VehicleMake()); DbContext.VehicleMakes.Add(make); DbContext.SaveChanges(); return(true); } return(false); }