public static GlnDto CreateGlnIncludeChildrenDto(Gln gln) { var glnDto = CreateBasicGlnDto(gln); if (!Equals(gln.Address, null)) { glnDto.Address = CreateAddressDto(gln.Address); } if (!Equals(gln.PrimaryContact, null)) { glnDto.PrimaryContact = CreatePrimaryContactDto(gln.PrimaryContact); } if (!Equals(gln.Parent, null)) { glnDto.Parent = CreateGlnSummaryDto(gln.Parent); } if (!Equals(gln.TierLevel, null)) { glnDto.TierLevel = gln.TierLevel.Value; } if (!Equals(gln.Children, null)) { glnDto.Children = gln.Children.Where(c => c.Assigned).OrderBy(c => c.FriendlyDescriptionPurpose).Select(CreateGlnSummaryDto).ToList(); } if (!Equals(gln.Tags, null)) { glnDto.Tags = gln.Tags.Where(t => t.Active).OrderBy(t => t.GlnTagType.Description).Select(CreateGlnTagDto).ToList(); } return(glnDto); }
private string TransformPrimaryContactIntoCsv(Gln gln) { var sb = new StringBuilder(); var name = gln.PrimaryContact.Name.Split(); sb.Append(gln.PrimaryContact.Salutation); sb.Append(", "); sb.Append(name.First()); sb.Append(", "); if (name.Length > 1) { sb.Append(name[1]); } sb.Append(", "); sb.Append(gln.PrimaryContact.Function); sb.Append(", "); sb.Append(gln.PrimaryContact.Email); sb.Append(", "); sb.Append(gln.PrimaryContact.Telephone); return(sb.ToString()); }
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); } }
private void GenerateFiveTierFamily() { // gln1 already created in the constructor _sentGln // So need to create five gln starting from id = 2 var id = 2; var gln2 = new Gln() { Id = 2, FriendlyDescriptionPurpose = id.ToString(), OwnGln = "tier" + 2.ToString(), Assigned = true, ParentId = 1 }; _dbContext.Glns.Add(gln2); _dbContext.SaveChanges(); // Create 2 children for tier2 GLN CreateNumberOfChildrenAddToParent(2, 2); var gln3 = new Gln() { Id = _dbContext.Glns.Count() + 1, FriendlyDescriptionPurpose = id.ToString(), OwnGln = "tier" + 3.ToString(), Assigned = true, ParentId = 2 }; _dbContext.Glns.Add(gln3); _dbContext.SaveChanges(); // Create 3 children for tier3 GLN CreateNumberOfChildrenAddToParent(3, 3); var gln4 = new Gln() { Id = _dbContext.Glns.Count() + 1, FriendlyDescriptionPurpose = id.ToString(), OwnGln = "tier" + 4.ToString(), Assigned = true, ParentId = 3 }; _dbContext.Glns.Add(gln4); _dbContext.SaveChanges(); // Create 4 children for tier4 GLN CreateNumberOfChildrenAddToParent(4, 4); var gln5 = new Gln() { Id = _dbContext.Glns.Count() + 1, FriendlyDescriptionPurpose = id.ToString(), OwnGln = "tier" + 5.ToString(), Assigned = true, ParentId = 4 }; _dbContext.Glns.Add(gln5); _dbContext.SaveChanges(); // Create 5 children for tier5 GLN CreateNumberOfChildrenAddToParent(5, 5); var getGln1 = _dbContext.Glns.SingleOrDefault(g => g.OwnGln == "tier1"); var getGln2 = _dbContext.Glns.SingleOrDefault(g => g.OwnGln == "tier2"); var getGln3 = _dbContext.Glns.SingleOrDefault(g => g.OwnGln == "tier3"); var getGln4 = _dbContext.Glns.SingleOrDefault(g => g.OwnGln == "tier4"); var getGln5 = _dbContext.Glns.SingleOrDefault(g => g.OwnGln == "tier5"); // This creates the 5 tier family structure getGln1.Children.Add(getGln2); getGln2.Children.Add(getGln3); getGln3.Children.Add(getGln4); getGln4.Children.Add(getGln5); _dbContext.SaveChanges(); }