Beispiel #1
0
        public static TicketEntities ToEntities(this Ticket Ticket)
        {
            var result = new TicketEntities
            {
                Contact     = Ticket.CreateContact(),
                Attachments = Ticket.Attachments != null?Ticket.Attachments.Select(item => TicketEntities.ToAttachment(item, Ticket)).ToList() : new List <tblAttachments>(),
                                  ResponseHistory = Ticket.ResponseHistory != null?Ticket.ResponseHistory.Select(item => TicketEntities.ToContactHistory(item, Ticket)).ToList() : new List <tblContactHistory>(),
                                                        ResearchHistory = Ticket.ResearchHistory != null?Ticket.ResearchHistory.Select(item => TicketEntities.ToResearchHistory(item, Ticket)).ToList() : new List <tblResearchHistory>(),
                                                                              LinkedContacts = Ticket.LinkedTickets != null?Ticket.LinkedTickets.Select(childTicket => TicketEntities.ToLinkedContact(Ticket, childTicket)).ToList() : new List <tblLinkedContacts>(),
                                                                                                   //ChangeHistory = Ticket.ChangeHistory != null ? Ticket.ChangeHistory.Select(item => TicketEntities.ToChangeHistory(item, Ticket)).ToList() : new List<tblUpdateLog>()
            };

            // merge ResponseHistory back to ContactStatus, if applicable
            if (Ticket.ResponseHistory != null)
            {
                var lastResponseHistory = Ticket.ResponseHistory.FirstOrDefault();
                if (lastResponseHistory != null && lastResponseHistory.Via.ToString() != result.Contact.ContactStatus)
                {
                    result.Contact.ContactStatus = lastResponseHistory.Via.ToString();
                }
            }

            return(result);
        }
Beispiel #2
0
        public static Ticket FromEntities(this TicketEntities TicketEntities, int?LinkedId = null)
        {
            if (TicketEntities == null)
            {
                return(null);
            }
            var contact = TicketEntities.Contact;

            // TODO: Use object initializer once code is proven accurate
            var ticket = new Ticket();

            ticket.Id       = contact.FileNum;
            ticket.LinkedId = LinkedId;
            ticket.Status   = contact.TicketStatus != null?contact.TicketStatus.NullableTrim().DescriptionToPascalCase().EnumParse(TicketStatus.New) : TicketStatus.New;

            ticket.Priority = contact.Priority.NullableTrim().EnumParse(TicketPriority.Normal);
            ticket.Source   = new TicketSource
            {
                ReceivedAt = contact.ReceivedDateTime,
                ReceivedBy = new User(Id: contact.UserId.NullOrWhiteSpaceTrim()),
                Via        = contact.ContactSource.NullableTrim().EnumParse(TicketSourceVia.WEB),
                FeedbackId = contact.FeedbackId
            };
            ticket.Contact = new Contact
            {
                Name = new Name
                {
                    First = contact.FirstName.NullOrWhiteSpaceTrim(),
                    Last  = contact.LastName.NullOrWhiteSpaceTrim()
                },
                Address = new Address
                {
                    Addr1   = contact.Addr1.NullOrWhiteSpaceTrim(),
                    Addr2   = contact.Addr2.NullOrWhiteSpaceTrim(),
                    City    = contact.CustCity.NullOrWhiteSpaceTrim(),
                    State   = contact.CustState.NullOrWhiteSpaceTrim(),
                    ZipCode = contact.CustZip.NullOrWhiteSpaceTrim(),
                },
                Email = contact.Email,
                Phone = new Phone
                {
                    Number = contact.CellPhone.NullOrWhiteSpaceTrim(),
                    Kind   = PhoneKind.Home
                },
                Status = contact.ContactStatus.NullableTrim()
            };
            ticket.IsAdaComplaint = contact.ADAComplaint == "Y";
            ticket.IsTitle6       = contact.TitleVI == "Y";
            ticket.Incident       = new Incident
            {
                IncidentAt    = contact.IncidentDateTime,
                VehicleNumber = contact.VehNo.NullOrWhiteSpaceTrim(),
                Route         = contact.Route.NullOrWhiteSpaceTrim(),
                Location      = contact.Location.NullOrWhiteSpaceTrim(),
                Destination   = contact.Destination.NullOrWhiteSpaceTrim(),
                City          = contact.IncidentCity.NullOrWhiteSpaceTrim(),
                Division      = contact.Division.NullOrWhiteSpaceTrim()
            };
            ticket.Operator = new Operator
            {
                Badge       = contact.Badge.NullOrWhiteSpaceTrim(),
                Description = contact.EmployeeDesc.NullOrWhiteSpaceTrim(),
                Name        = contact.OperatorName.NullOrWhiteSpaceTrim(),
            };
            ticket.LostItem = new LostItem
            {
                Category                       = contact.LostItemCategory != null?contact.LostItemCategory.NullableTrim() : null,
                                          Type = contact.LostItemType != null?contact.LostItemType.NullableTrim() : null,
            };
            ticket.Reasons          = contact.Reasons != null ? new List <string>(contact.Reasons.Split(new[] { ';' })) : null;
            ticket.Comments         = contact.CustComments;
            ticket.ResponseCriteria = new ResponseCriteria
            {
                HasRequestedResponse = contact.ResponseRequested == "Y",
                Via = ParseResponseCriteriaVia(contact.RespondVia)
            };
            ticket.Resolution = new Resolution
            {
                Action     = contact.Resolution.NullOrWhiteSpaceTrim(),
                Comment    = contact.ResolutionComment.NullOrWhiteSpaceTrim(),
                ResolvedAt = contact.ResolvedDateTime
            };
            ticket.Assignment = new Assignment
            {
                GroupContact = new GroupContact(contact.ForAction.NullOrWhiteSpaceTrim()),
                Employee     = new User(Id: contact.AssignedTo.NullOrWhiteSpaceTrim())
            };
            ticket.ResponseHistory = TicketEntities.ResponseHistory != null?TicketEntities.ResponseHistory.Select(ch => TicketEntities.FromContactHistory(ch, contact.ContactStatus)).OrderByDescending(rh => rh.ResponseAt).ToList() : null;

            ticket.Attachments = TicketEntities.Attachments != null?TicketEntities.Attachments.Select(TicketEntities.FromAttachment).ToList() : null;

            ticket.ResearchHistory = TicketEntities.ResearchHistory != null?TicketEntities.ResearchHistory.Select(TicketEntities.FromResearchHistory).OrderByDescending(rh => rh.ResearchedAt).ToList() : null;

            ticket.LinkedTickets = TicketEntities.LinkedContacts != null?TicketEntities.FromLinkedContacts(TicketEntities.LinkedContacts, contact.FileNum) : null;

            ticket.UpdatedAt     = contact.updatedOn;
            ticket.ChangeHistory = TicketEntities.ChangeHistory != null?TicketEntities.ChangeHistory.Select(TicketEntities.FromChangeHistory).OrderByDescending(ch => ch.ChangeAt).ThenBy(ch => ch.ColumnName).ToList() : null;

            ticket.UpdatedBy = new User(Id: contact.updatedBy.NullOrWhiteSpaceTrim());
            ticket.DaysOpen  = (
                (contact.ResolvedDateTime.HasValue
                ? contact.ResolvedDateTime.GetValueOrDefault().Date
                : DateTime.Now.Date) - contact.ReceivedDateTime.GetValueOrDefault().Date).Days;

            return(ticket);
        }