public IActionResult CreateGhostbuster([FromBody] GhostbusterInputModel ghostbuster) { if (!ModelState.IsValid) { throw new ModelFormatException(ModelState.RetrieveErrorString()); } var newId = _ghostbusterService.CreateGhostbuster(ghostbuster); return(CreatedAtRoute("GetGhostbusterById", new { id = newId }, null)); }
public int CreateGhostbuster(GhostbusterInputModel ghostbuster) { var nextId = _dbContext.Ghostbusters.Count() + 1; _dbContext.Ghostbusters.Add(new Ghostbuster { Id = nextId, Name = ghostbuster.Name, Expertize = ghostbuster.Expertize }); return(nextId); }
/// <summary> /// Determines if provided expertize for model is valid /// </summary> /// <param name="value"></param> /// <param name="validationContext"></param> /// <returns>Validation result - indicates success if expertize property was valid otherwise failure</returns> protected override ValidationResult IsValid(object value, ValidationContext validationContext) { GhostbusterInputModel ghostbuster = (GhostbusterInputModel)validationContext.ObjectInstance; if (_validExpertizes.FirstOrDefault(x => x == ghostbuster.Expertize) == null) { return(new ValidationResult(GetErrorMessage(ghostbuster.Expertize))); } else { return(ValidationResult.Success); } }
public int CreateGhostbuster(GhostbusterInputModel ghostbuster) => _ghostbusterRepository.CreateGhostbuster(ghostbuster);