public async Task <SavePersonResponse> Save([FromBody] SavePersonRequest request) { SavePersonResponse response = new SavePersonResponse(); if (response.InitializeFromModelStateIfInvalid(ModelState)) { return(response); } if (request.Person.ID == Guid.Empty) { request.Person.ID = Guid.NewGuid(); await _personUpsert.ExecuteAsync(request.Person, true); } else { var existingSite = _personSearch.Execute(new PersonSearchCriteria { IncludedPersonIDs = new List <Guid> { request.Person.ID } }).FirstOrDefault(); await _personUpsert.ExecuteAsync(request.Person); } response.Person = request.Person; return(response); }
public async Task <SavePersonResponse> SavePerson(SavePersonRequest request) { const string userMessage = "Unable to save Person"; var response = new SavePersonResponse(); try { var p = await _dbContext.People.FindAsync(request.Person.Id); if (p == null) { p = new People { Id = Guid.NewGuid() }; _dbContext.People.Add(p); } else { _dbContext.Entry(p).State = EntityState.Modified; } p.FirstName = request.Person.FirstName; p.LastName = request.Person.LastName; p.Email = request.Person.Email; p.Photo = request.Person.Photo; await _dbContext.SaveChangesAsync(); response.Success = true; response.Id = p.Id; return(response); } catch (Exception ex) { //log the exception.. //In production we wouldn't return the exception detail return(new SavePersonResponse { Success = false, FailureInformation = userMessage + " | " + ex.Message }); } }
public async Task SavePersonAsync(Person person) { var request = new SavePersonRequest(MapPersonToPersonDto(person)); await clientProxy.Execute(client => client.SavePersonAsync(request)); }
public void SavePerson(Person person) { var request = new SavePersonRequest(MapPersonToPersonDto(person)); clientProxy.Execute(client => client.SavePerson(request)); }
//api/data/SavePerson/ + body public async Task <SavePersonResponse> SavePerson([FromBody] SavePersonRequest request) { return(await _repository.SavePerson(request)); }