Пример #1
0
        public GlnDto GetGlnByGln(string gln)
        {
            var findGlns = _db.Glns.SingleOrDefault(b => b.OwnGln == gln);

            if (!Equals(findGlns, null))
            {
                //Everytime gln is fetched calculate its children to ensure it is up to date
                var currentDbVersion = _db.Glns.SingleOrDefault(bc => bc.OwnGln == gln).Version;
                if (ConcurrencyChecker.canSaveChanges(findGlns.Version, currentDbVersion))
                {
                    findGlns.NumberOfChildren = CalculateChildrenNumbers(findGlns.OwnGln);
                }

                // If primary then GLN will not have a parent
                if (!findGlns.Primary)
                {
                    findGlns.ParentDescriptionPurpose =
                        _db.Glns.SingleOrDefault(bc => bc.OwnGln == findGlns.ParentGln).FriendlyDescriptionPurpose;
                }

                _db.SaveChanges();
            }

            return(DtoHelper.CreateGlnIncludeChildrenDto(findGlns));
        }
Пример #2
0
        public GlnDto GetGlnById(int id)
        {
            var gln = _db.Glns.SingleOrDefault(b => b.Id == id);

            if (!Equals(gln, null))
            {
                //Everytime gln is fetched calculate its children to ensure it is up to date
                var currentDbVersion = _db.Glns.SingleOrDefault(bc => bc.Id == id).Version;
                if (ConcurrencyChecker.canSaveChanges(gln.Version, currentDbVersion))
                {
                    gln.NumberOfChildren = CalculateChildrenNumbers(gln.OwnGln);
                }

                // If primary then GLN will not have a parent
                try
                {
                    if (!gln.Primary)
                    {
                        gln.ParentDescriptionPurpose =
                            _db.Glns.SingleOrDefault(bc => bc.OwnGln == gln.ParentGln).FriendlyDescriptionPurpose;
                    }

                    _db.SaveChanges();
                }
                catch (Exception ex)
                {
                    var failedMsg = $"Failed to update Parent Description Purpose on {gln.OwnGln} " +
                                    $". Exception generated: {ex}";

                    _mongoMongoLogger.FailedUpdateServerLog <Exception, string, object>(HttpContext.Current.User, ex.Message, ex.InnerException, failedMsg);
                }
            }

            return(DtoHelper.CreateGlnIncludeChildrenDto(gln));
        }
        public HttpStatusCode UpdateAdditionalContact(AdditionalContact additionalContact)
        {
            var systemManagerToUpdate     = _db.AdditionalContacts.SingleOrDefault(sm => sm.Id == additionalContact.Id);
            var systemManagerBeforeUpdate = DtoHelper.CreateAdditionalContactDto(systemManagerToUpdate);

            if (Equals(systemManagerToUpdate, null))
            {
                return(HttpStatusCode.BadRequest);
            }

            try
            {
                if (ConcurrencyChecker.canSaveChanges(additionalContact.Version, systemManagerToUpdate.Version))
                {
                    systemManagerToUpdate.Name                   = additionalContact.Name;
                    systemManagerToUpdate.Email                  = additionalContact.Email;
                    systemManagerToUpdate.Telephone              = additionalContact.Telephone;
                    systemManagerToUpdate.System                 = additionalContact.System;
                    systemManagerToUpdate.Fax                    = additionalContact.Fax;
                    systemManagerToUpdate.Salutation             = additionalContact.Salutation;
                    systemManagerToUpdate.Version                = additionalContact.Version + 1;
                    systemManagerToUpdate.Role                   = additionalContact.Role;
                    systemManagerToUpdate.NotificationSubscriber = additionalContact.NotificationSubscriber;
                    systemManagerToUpdate.Active                 = additionalContact.Active;

                    _db.SaveChanges();

                    _mongoMongoLogger.SuccessfulUpdateServerLog(HttpContext.Current.User, systemManagerBeforeUpdate, DtoHelper.CreateAdditionalContactDto(systemManagerToUpdate));

                    return(HttpStatusCode.OK);
                }
                else
                {
                    _mongoMongoLogger.ConcurrenyServerLog <object, object>(HttpContext.Current.User, additionalContact);

                    return(HttpStatusCode.Conflict);
                }
            }
            catch (Exception ex)
            {
                _mongoMongoLogger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message, ex.InnerException, additionalContact);

                return(HttpStatusCode.InternalServerError);
            }
        }
Пример #4
0
        public HttpStatusCode AssignNewGln(int contactId, int addressId, Gln gln)
        {
            if (contactId <= 0)
            {
                return(HttpStatusCode.BadRequest);
            }

            if (addressId <= 0)
            {
                return(HttpStatusCode.BadRequest);
            }

            var glnToUpdate      = _db.Glns.SingleOrDefault(b => b.Id == gln.Id);
            var glnBeforeUpdate  = DtoHelper.CreateGlnIncludeChildrenDto(glnToUpdate);
            var currentDbVersion = glnToUpdate.Version;

            try
            {
                if (ConcurrencyChecker.canSaveChanges(gln.Version, currentDbVersion))
                {
                    glnToUpdate.Assigned = true;
                    glnToUpdate.Active   = gln.Active;
                    glnToUpdate.FriendlyDescriptionPurpose = gln.FriendlyDescriptionPurpose;
                    glnToUpdate.FunctionalType             = gln.FunctionalType;
                    glnToUpdate.LegalType        = gln.LegalType;
                    glnToUpdate.PhysicalType     = gln.PhysicalType;
                    glnToUpdate.DigitalType      = gln.DigitalType;
                    glnToUpdate.Public           = gln.Public;
                    glnToUpdate.ParentGln        = gln.ParentGln;
                    glnToUpdate.AddressId        = gln.AddressId;
                    glnToUpdate.ContactId        = gln.ContactId;
                    glnToUpdate.UseParentAddress = gln.UseParentAddress;
                    glnToUpdate.Version          = gln.Version + 1;
                    glnToUpdate.TrustActive      = gln.TrustActive;
                    glnToUpdate.SuspensionReason = gln.SuspensionReason;
                    glnToUpdate.Function         = gln.Function;
                    glnToUpdate.Department       = gln.Department;
                    glnToUpdate.TierLevel        = gln.TierLevel;
                    //Calculate how many children this gln has
                    glnToUpdate.NumberOfChildren = CalculateChildrenNumbers(glnToUpdate.OwnGln);
                    glnToUpdate.ParentGln        = _db.Glns.SingleOrDefault(bc => bc.Primary).OwnGln;

                    _db.SaveChanges();

                    _mongoMongoLogger.SuccessfulUpdateServerLog(HttpContext.Current.User, glnBeforeUpdate, DtoHelper.CreateGlnIncludeChildrenDto(glnToUpdate));

                    return(HttpStatusCode.OK);
                }
                else
                {
                    _mongoMongoLogger.ConcurrenyServerLog <object, object>(HttpContext.Current.User, glnBeforeUpdate);
                    return(HttpStatusCode.Conflict);
                }
            }
            catch (Exception ex)
            {
                var failedMsg = $"Failed to assign new GLN {glnToUpdate.OwnGln}, {glnToUpdate.FriendlyDescriptionPurpose}.";

                _mongoMongoLogger.FailedUpdateServerLog <Exception, string, object>(HttpContext.Current.User, ex.Message, ex.InnerException, failedMsg);

                return(HttpStatusCode.InternalServerError);
            }
        }