public IHttpActionResult PutById([FromUri] int id, [FromBody] CreateDemographicModel command) { if (command == null || !ModelState.IsValid) { return(this.Error().InvalidParameters()); } var d = _demographicRepository.GetById(id); if (d == null) { return(NotFound()); } d.ExternalRef = command.ExternalRef; d.Update(command.Name, command.ShortName, command.DisplayOrder, command.Gameplan); ValidateForSave(d); // Check that ExternalRef is unique var d2 = _demographicRepository.GetByExternalRef(d.ExternalRef); if (d2 != null && d2.Id != d.Id) { return(this.Error().InvalidParameters("ExternalRef must be unique")); } _demographicRepository.Update(d); return(Ok()); }
public IHttpActionResult PutByExternalRef([FromUri] string externalRef, [FromBody] CreateDemographicModel command) { if (command == null || !ModelState.IsValid) { return(this.Error().InvalidParameters()); } var d = _demographicRepository.GetByExternalRef(externalRef); if (d == null) { return(NotFound()); } d.Update(command.Name, command.ShortName, command.DisplayOrder, command.Gameplan); ValidateForSave(d); _demographicRepository.Update(d); return(Ok()); }