public UpdateAddressBookEntryResult UpdateAddressBookEntry(UpdateAddressCommandParameters parameters) { using (var uow = _unitOfWorkFactory.Invoke()) { var addressBookEntry = uow.AddressBookEntries.Load(parameters.Id); if (addressBookEntry == null) { return(new UpdateAddressBookEntryResult { ResultType = AddressBookCommandResultType.Error, Error = "This address book entry was not found." }); } addressBookEntry.Update(parameters.FirstName, parameters.LastName, parameters.Street1, parameters.Street2, parameters.City, parameters.State, parameters.ZipCode, parameters.HomePhone, parameters.MobilePhone, parameters.Email); uow.AddressBookEntries.Update(addressBookEntry); uow.Commit(); return(new UpdateAddressBookEntryResult { ResultType = AddressBookCommandResultType.Success }); } }
public HttpResponseMessage UpdateAddressBookEntry(UpdateAddressCommandParameters parameters) { try { Logger.Trace("UpdateAddressBookEntry started through Web API"); if (parameters == null) { const string nullParametersErrorMsg = "UpdateAddressBookEntry called with null parameters"; Logger.Info(nullParametersErrorMsg); return(Request.CreateResponse(HttpStatusCode.BadRequest, new AddAddressBookEntryResult { Error = nullParametersErrorMsg })); } if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(v => v.Errors.Select(e => e.ErrorMessage)).ToList(); Logger.Info("UpdateAddressBookEntry called with invalid parameters: {0}", string.Join(", ", errors)); return(Request.CreateResponse(HttpStatusCode.BadRequest, new AddAddressBookEntryResult { ValidationErrors = errors })); } var canUpdate = Authorization.IsAuthorized(UserId, ActivityEnum.Update); if (!canUpdate) { return(Request.CreateResponse(HttpStatusCode.Forbidden)); } var result = _addressBookService.UpdateAddressBookEntry(parameters); if (result.ResultType == AddressBookCommandResultType.Error) { Logger.Error("UpdateAddressBookEntry failed with error: {0}", result.Error); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Unexpected server error")); } Logger.Trace("UpdateAddressBookEntry creating response"); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { Logger.Error(ex, "UpdateAddressBookEntry failed"); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Unexpected server error")); } }