示例#1
0
        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());
            }
        }
示例#3
0
        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)));
        }
示例#4
0
        public IHttpActionResult PutGlnTag(GlnTag glnTag)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var tagToBeUpdated = _unitOfWork.GlnTag.FindSingle(t => t.GlnTagId == glnTag.GlnTagId);

            if (Equals(tagToBeUpdated, null))
            {
                return(NotFound());
            }

            var beforeUpdate = DtoHelper.CreateGlnTagDto(tagToBeUpdated);

            if (TagAlreadyExistOnGln(DtoHelper.CreateGlnTagDto(glnTag)))
            {
                _logger.FailedToCreateServerLog(HttpContext.Current.User, $"GLN already has this tag associated with it.", "", DtoHelper.CreateGlnTagDto(glnTag));
                return(BadRequest($"GLN already has this tag associated with it."));
            }

            tagToBeUpdated.Active           = glnTag.Active;
            tagToBeUpdated.GlnId            = glnTag.GlnId;
            tagToBeUpdated.GlnTagTypeId     = glnTag.GlnTagTypeId;
            tagToBeUpdated.TypeKey          = glnTag.TypeKey;
            tagToBeUpdated.ModifiedDateTime = DateTime.Now;
            tagToBeUpdated.UserModified     = HttpContext.Current.User.ToString();

            _unitOfWork.GlnTag.Update(tagToBeUpdated);

            try
            {
                _unitOfWork.Complete();
                _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, beforeUpdate, DtoHelper.CreateGlnTagDto(tagToBeUpdated));
            }
            catch (DbUpdateConcurrencyException)
            {
                _logger.FailedToCreateServerLog(HttpContext.Current.User, "Unable to create new tag type", "", DtoHelper.CreateGlnTagDto(tagToBeUpdated));
                return(InternalServerError());
            }

            return(Ok(DtoHelper.CreateGlnTagDto(tagToBeUpdated)));
        }
示例#5
0
        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());
            }
        }
        public IHttpActionResult UpdatePrimaryContact(PrimaryContact contact)
        {
            if (Equals(contact, null))
            {
                return(BadRequest());
            }

            var contactToUpdate = _unitOfWork.PrimaryContacts.FindSingle(pc => pc.Id == contact.Id);

            if (Equals(contactToUpdate, null))
            {
                return(BadRequest());
            }

            var contactBeforeUpdate = DtoHelper.CreatePrimaryContactDto(contactToUpdate);

            try
            {
                contactToUpdate.Name       = contact.Name;
                contactToUpdate.Email      = contact.Email;
                contactToUpdate.Telephone  = contact.Telephone;
                contactToUpdate.Function   = contact.Function;
                contactToUpdate.Salutation = contact.Salutation;
                contactToUpdate.Fax        = contact.Fax;
                contactToUpdate.Active     = contact.Active;
                contactToUpdate.Version    = contactToUpdate.Version + 1;

                _unitOfWork.Complete();

                _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, contactBeforeUpdate, DtoHelper.CreatePrimaryContactDto(_unitOfWork.PrimaryContacts.FindSingle(pc => pc.Id == contact.Id)));

                return(Ok(DtoHelper.CreatePrimaryContactDto(contactToUpdate)));
            }
            catch (Exception ex)
            {
                _logger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message,
                                                                          ex.InnerException, contact);

                return(InternalServerError());
            }
        }
        public IHttpActionResult PutGlnTagType(GlnTagTypeDto glnTagType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var tagTypeToBeUpdated = _unitOfWork.GlnTagType.FindSingle(tt => tt.GlnTagTypeId == glnTagType.GlnTagTypeId);

            if (Equals(tagTypeToBeUpdated, null))
            {
                return(NotFound());
            }

            var beforeUpdate = DtoHelper.CreateGlnTagTypeDto(tagTypeToBeUpdated);

            tagTypeToBeUpdated.Code             = glnTagType.Code;
            tagTypeToBeUpdated.Description      = glnTagType.Description;
            tagTypeToBeUpdated.ModifiedDateTime = DateTime.Now;
            tagTypeToBeUpdated.UserModified     = HttpContext.Current.User.ToString();
            tagTypeToBeUpdated.Active           = glnTagType.Active;

            _unitOfWork.GlnTagType.Update(tagTypeToBeUpdated);

            try
            {
                _unitOfWork.Complete();
                _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, beforeUpdate, DtoHelper.CreateGlnTagTypeDto(tagTypeToBeUpdated));
            }
            catch (DbUpdateConcurrencyException)
            {
                _logger.FailedToCreateServerLog(HttpContext.Current.User, "Unable to create new tag type", "", DtoHelper.CreateGlnTagTypeDto(tagTypeToBeUpdated));
                return(InternalServerError());
            }

            return(Ok(DtoHelper.CreateGlnTagTypeDto(tagTypeToBeUpdated)));
            //return StatusCode(HttpStatusCode.NoContent);
        }