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 override void Handle(IDemographicUpdated command) { var existingDemographic = _demographicsRepository.CheckDemographicByExternalRef(command.ExternalRef); existingDemographic.Update(command.Name, command.ShortName, command.DisplayOrder, command.Gameplan); _demographicsRepository.Update(existingDemographic); _demographicsRepository.SaveChanges(); }