public IHttpActionResult UpdateGln(Gln gln) { if (Equals(gln, null)) { return(BadRequest()); } var glnToUpdate = _unitOfWork.Glns.FindSingle(g => g.Id == gln.Id); var glnBeforeUpdate = DtoHelper.CreateGlnIncludeChildrenDto(glnToUpdate); if (Equals(glnToUpdate, null)) { return(BadRequest()); } var currentDbVersion = glnToUpdate.Version; if (!ConcurrencyChecker.canSaveChanges(gln.Version, currentDbVersion)) { _logger.ConcurrenyServerLog(HttpContext.Current.User, gln.Version, currentDbVersion); return(Conflict()); } var updatedGln = _unitOfWork.Glns.UpdateGln(gln); try { _unitOfWork.Complete(); var completed = _unitOfWork.Glns.FindSingle(g => g.Id == gln.Id); _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, glnBeforeUpdate, DtoHelper.CreateGlnDto(completed)); if (glnBeforeUpdate.ParentGln != glnToUpdate.ParentGln) { if (!string.IsNullOrEmpty(glnBeforeUpdate.ParentGln)) { // Update number of children on previous parent var oldParent = _unitOfWork.Glns.FindSingle(g => g.OwnGln == glnBeforeUpdate.ParentGln); oldParent.NumberOfChildren = _unitOfWork.Glns.Find(g => g.ParentGln == oldParent.OwnGln).Count(); _unitOfWork.Complete(); } if (!string.IsNullOrEmpty(glnToUpdate.ParentGln)) { // Update number of children on new parent that has aquired an additional child var newParent = _unitOfWork.Glns.FindSingle(g => g.OwnGln == glnToUpdate.ParentGln); newParent.NumberOfChildren = _unitOfWork.Glns.Find(g => g.ParentGln == newParent.OwnGln).Count(); _unitOfWork.Complete(); } } return(Ok(DtoHelper.CreateGlnIncludeChildrenDto(completed))); } catch (Exception ex) { _logger.FailedUpdateServerLog(HttpContext.Current.User, ex.Message, ex.InnerException, DtoHelper.CreateGlnDto(glnToUpdate), DtoHelper.CreateGlnIncludeChildrenDto(updatedGln)); return(InternalServerError()); } }
public IHttpActionResult UpdateAdditionalContact(AdditionalContact additionalContact) { if (Equals(additionalContact, null)) { return(BadRequest()); } var additionalContactToUpdate = _unitOfWork.AdditionalContacts.FindSingle(ac => ac.Id == additionalContact.Id); if (additionalContactToUpdate == null) { return(BadRequest()); } var additionalContactBeforeUpdate = DtoHelper.CreateAdditionalContactDto(additionalContact); try { if (ConcurrencyChecker.canSaveChanges(additionalContact.Version, additionalContactToUpdate.Version)) { additionalContactToUpdate.Name = additionalContact.Name; additionalContactToUpdate.Email = additionalContact.Email; additionalContactToUpdate.Telephone = additionalContact.Telephone; additionalContactToUpdate.System = additionalContact.System; additionalContactToUpdate.Fax = additionalContact.Fax; additionalContactToUpdate.Salutation = additionalContact.Salutation; additionalContactToUpdate.Version = additionalContact.Version + 1; additionalContactToUpdate.Role = additionalContact.Role; additionalContactToUpdate.NotificationSubscriber = additionalContact.NotificationSubscriber; additionalContactToUpdate.Active = additionalContact.Active; _unitOfWork.Complete(); _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, DtoHelper.CreateAdditionalContactDto(additionalContact), DtoHelper.CreateAdditionalContactDto(additionalContactToUpdate)); return(Ok(DtoHelper.CreateAdditionalContactDto(additionalContactToUpdate))); } else { _logger.ConcurrenyServerLog <object, object>(HttpContext.Current.User, additionalContact); return(Conflict()); } } catch (Exception ex) { _logger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message, ex.InnerException, DtoHelper.CreateAdditionalContactDto(additionalContact)); return(InternalServerError()); } }
public IHttpActionResult UpdateAddress(Address address) { if (Equals(address, null)) { return(BadRequest()); } var addressToUpdate = _unitOfWork.Addresses.FindSingle(a => a.Id == address.Id); if (Equals(addressToUpdate, null)) { return(NotFound()); } if (!ConcurrencyChecker.canSaveChanges(address.Version, addressToUpdate.Version)) { _logger.ConcurrenyServerLog <object, object>(HttpContext.Current.User, address); return(Conflict()); } var addressBeforeUpdate = DtoHelper.CreateAddressDto(address); try { addressToUpdate.Active = address.Active; addressToUpdate.AddressLineOne = address.AddressLineOne; addressToUpdate.AddressLineTwo = address.AddressLineTwo; addressToUpdate.AddressLineThree = address.AddressLineThree; addressToUpdate.AddressLineFour = address.AddressLineFour; addressToUpdate.City = address.City; addressToUpdate.Country = address.Country; addressToUpdate.RegionCounty = address.RegionCounty; addressToUpdate.Postcode = address.Postcode; addressToUpdate.Version = addressToUpdate.Version + 1; addressToUpdate.Level = address.Level; addressToUpdate.DeliveryNote = address.DeliveryNote; _unitOfWork.Complete(); _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, addressBeforeUpdate, DtoHelper.CreateAddressDto(addressToUpdate)); } catch (Exception ex) { _logger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message, ex.InnerException, DtoHelper.CreateAddressDto(address)); } return(Ok(DtoHelper.CreateAddressDto(addressToUpdate))); }
public IHttpActionResult MobileUpdateGln(Gln gln) { if (Equals(gln, null)) { return(BadRequest()); } var glnToUpdate = _unitOfWork.Glns.FindSingle(g => g.Id == gln.Id); var glnBeforeUpdate = DtoHelper.CreateGlnIncludeChildrenDto(glnToUpdate); if (Equals(glnToUpdate, null)) { return(BadRequest()); } var currentDbVersion = glnToUpdate.Version; glnToUpdate.FriendlyDescriptionPurpose = gln.FriendlyDescriptionPurpose; if (!ConcurrencyChecker.canSaveChanges(gln.Version, currentDbVersion)) { _logger.ConcurrenyServerLog(HttpContext.Current.User, gln.Version, currentDbVersion); return(Conflict()); } glnToUpdate.Version = currentDbVersion + 1; try { _unitOfWork.Complete(); var completed = _unitOfWork.Glns.FindSingle(g => g.Id == gln.Id); _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, glnBeforeUpdate, DtoHelper.CreateGlnIncludeChildrenDto(completed)); return(Ok(DtoHelper.CreateGlnIncludeChildrenDto(completed))); } catch (Exception ex) { _logger.FailedUpdateServerLog(HttpContext.Current.User, ex.Message, ex.InnerException, DtoHelper.CreateGlnIncludeChildrenDto(glnToUpdate), DtoHelper.CreateGlnIncludeChildrenDto(glnToUpdate)); return(InternalServerError()); } }