Ejemplo n.º 1
0
 private ReportInvoiceVM GetReportInvoiceVM(Lead lead, LeadAssignment assignment
                                            , LeadState submittedState, LeadAssignmentState assignedState, LeadAssignmentState acceptedState
                                            , LeadAssignmentState currentState, StateAction currentAction)
 {
     return(new ReportInvoiceVM()
     {
         LeadId = lead.Id,
         LeadDetails = lead.Details,
         SubmittedDateTime = DateHelper.ConvertFromUtc(submittedState.ActionTimestamp),
         SubmittedDateTimeString = DateHelper.ConvertFromUtc(submittedState.ActionTimestamp).ToShortDateString() + " " + DateHelper.ConvertFromUtc(submittedState.ActionTimestamp).ToShortTimeString(),
         LeadTypeId = lead.LeadType.Id,
         LeadTypeName = lead.LeadType.Name,
         LeadTypeImage = ImageHelper.PATH_CLIENT_LEAD_TYPE + lead.LeadType.Image,
         LeadTypePrice = lead.LeadType.Price,
         CustomerId = lead.Customer.Id,
         CustomerUnique = lead.Customer.ContactName + " (" + lead.Customer.EMail + ")",
         CustomerName = lead.Customer.ContactName,
         CustomerContactNumber = lead.Customer.ContactNumber,
         CustomerEmail = lead.Customer.EMail,
         CustomerBusinessName = lead.Customer.BusinessName,
         CustomerState = lead.Customer.Address.State,
         CustomerAddress = AddressHelper.MergeAddress(lead.Customer.Address),
         PartnerId = assignment.PartnerBranch.Partner.Id,
         PartnerName = assignment.PartnerBranch.Partner.Name,
         PartnerLogo = ImageHelper.PATH_CLIENT_PARTNER + assignment.PartnerBranch.Partner.Logo,
         PartnerAddress = AddressHelper.MergeAddress(assignment.PartnerBranch.Address),
         LeadAssignmentId = assignment.Id,
         AssignedDateTime = DateHelper.ConvertFromUtc(assignedState.ActionTimestamp),
         AssignedDateTimeString = DateHelper.ConvertFromUtc(assignedState.ActionTimestamp).ToShortDateString() + " " + DateHelper.ConvertFromUtc(assignedState.ActionTimestamp).ToShortTimeString(),
         AcceptedDateTime = DateHelper.ConvertFromUtc(acceptedState.ActionTimestamp),
         AcceptedDateTimeString = DateHelper.ConvertFromUtc(acceptedState.ActionTimestamp).ToShortDateString() + " " + DateHelper.ConvertFromUtc(acceptedState.ActionTimestamp).ToShortTimeString(),
         CurrentStateId = currentState.State.Id,
         CurrentStateName = currentState.State.Name,
         CurrentStateTag = StatusHelper.GetHtmlBadge(currentState.State.Id, currentState.State.Name),
         CurrentActionId = currentAction.Action.Id,
         CurrentActionName = currentAction.Action.ActionName
     });
 }
Ejemplo n.º 2
0
        public LeadVM GetLeadViewModel(Lead item)
        {
            var itemVM = new LeadVM();

            itemVM.Id      = item.Id;
            itemVM.Details = item.Details;

            itemVM.LeadTypeId    = item.LeadType.Id;
            itemVM.LeadTypeName  = item.LeadType.Name;
            itemVM.LeadTypeImage = ImageHelper.PATH_CLIENT_LEAD_TYPE + item.LeadType.Image;

            itemVM.CustomerId     = item.Customer.Id;
            itemVM.CustomerUnique = String.Format("{0} ({1})", item.Customer.ContactName, item.Customer.EMail);

            itemVM.CustomerName          = item.Customer.ContactName;
            itemVM.CustomerBusinessName  = item.Customer.BusinessName;
            itemVM.CustomerContactNumber = item.Customer.ContactNumber;
            itemVM.CustomerEmail         = item.Customer.EMail;

            itemVM.CustomerAddress = AddressHelper.MergeAddress(item.Customer.Address.StreetAddress, item.Customer.Address.Suburb, item.Customer.Address.State, item.Customer.Address.PostCode);
            itemVM.CustomerDetails = String.Format("Business: <b>{0}</b><br>Tel: <b>{1}</b><br>Address: <b>{2}</b>", itemVM.CustomerBusinessName, itemVM.CustomerContactNumber, itemVM.CustomerAddress);

            // Current status
            var currentStatus = item.LeadStates.Where(w => w.StateId != nameof(EnumState.S0)).OrderByDescending(o => o.ActionTimestamp).FirstOrDefault();

            itemVM.StatusId   = currentStatus.State.Id;
            itemVM.StatusName = currentStatus.State.Name;
            itemVM.StatusTag  = StatusHelper.GetHtmlBadge(currentStatus.State.Id, currentStatus.State.Name);

            // Actions of current status
            var actions = currentStatus.State.StateActions.Select(s => new ActionLeadVM
            {
                Id             = s.ActionId,
                CustomerId     = itemVM.CustomerId,
                CustomerEmail  = itemVM.CustomerEmail,
                LeadId         = itemVM.Id,
                ControllerName = s.Action.ControllerName,
                ActionName     = s.Action.ActionName,
                ActionTarget   = s.Action.ActionTarget,
                RequestType    = s.Action.RequestType,
                DisplayName    = s.Action.DisplayName,
                Icon           = s.Action.Icon,
                NextStateId    = s.Action.NextStateId
            }).ToList();

            itemVM.Actions = actions;

            // CreatedWhen
            var createdStatus = item.LeadStates.OrderBy(o => o.ActionTimestamp).FirstOrDefault();

            itemVM.CreatedOn = DateHelper.ConvertFromUtc(createdStatus.ActionTimestamp).Date;

            // Histories
            var histories = item.LeadStates
                            .OrderByDescending(o => o.ActionTimestamp)
                            //.Where(w => w.StateId != currentStatus.StateId) // *show all
                            .Select(s => HistoryHelper.GetHtmlHistoryLine(DateHelper.ConvertFromUtc(s.ActionTimestamp), s.Action.ToLower(), s.Actor));

            itemVM.History = HistoryHelper.GetHtmlHistoryTag(histories.ToList());

            return(itemVM);
        }
Ejemplo n.º 3
0
        protected LeadAssignmentVM GetLeadAssignmentViewModel(LeadAssignment item)
        {
            var itemVM = new LeadAssignmentVM();

            itemVM.Id     = item.Id;
            itemVM.LeadId = item.LeadId;

            if (item.Lead != null)
            {
                itemVM.LeadDetails = item.Lead.Details;

                if (item.Lead.LeadType != null)
                {
                    itemVM.LeadTypeName  = item.Lead.LeadType.Name;
                    itemVM.LeadTypeImage = ImageHelper.PATH_CLIENT_LEAD_TYPE + item.Lead.LeadType.Image;
                }

                if (item.Lead.Customer != null)
                {
                    itemVM.CustomerId     = item.Lead.Customer.Id;
                    itemVM.CustomerUnique = String.Format("{0} ({1})", item.Lead.Customer.ContactName, item.Lead.Customer.EMail);

                    itemVM.CustomerName          = item.Lead.Customer.ContactName;
                    itemVM.CustomerBusinessName  = item.Lead.Customer.BusinessName;
                    itemVM.CustomerEMail         = item.Lead.Customer.EMail;
                    itemVM.CustomerContactNumber = item.Lead.Customer.ContactNumber;
                    itemVM.CustomerStreetAddress = item.Lead.Customer.Address.StreetAddress;
                    itemVM.CustomerSuburb        = item.Lead.Customer.Address.Suburb;
                    itemVM.CustomerState         = item.Lead.Customer.Address.State;
                    itemVM.CustomerPostCode      = item.Lead.Customer.Address.PostCode;
                    itemVM.CustomerAddress       = AddressHelper.MergeAddress(itemVM.CustomerStreetAddress, itemVM.CustomerSuburb, itemVM.CustomerState, itemVM.CustomerPostCode);

                    itemVM.CustomerDetails = String.Format("Business: <b>{0}</b><br>Tel: <b>{1}</b><br>Address: <b>{2}</b>", itemVM.CustomerBusinessName, itemVM.CustomerContactNumber, itemVM.CustomerAddress);
                }
            }

            itemVM.PartnerId   = item.PartnerBranch.Partner.Id;
            itemVM.PartnerName = item.PartnerBranch.Partner.Name;
            itemVM.PartnerLogo = ImageHelper.PATH_CLIENT_PARTNER + item.PartnerBranch.Partner.Logo;

            itemVM.PartnerBranchId            = item.PartnerBranch.Id;
            itemVM.PartnerBranchStreetAddress = item.PartnerBranch.Address.StreetAddress;
            itemVM.PartnerBranchSuburb        = item.PartnerBranch.Address.Suburb;
            itemVM.PartnerBranchState         = item.PartnerBranch.Address.State;
            itemVM.PartnerBranchPostCode      = item.PartnerBranch.Address.PostCode;
            itemVM.PartnerBranchAddress       = AddressHelper.MergeAddress(itemVM.PartnerBranchStreetAddress, itemVM.PartnerBranchSuburb, itemVM.PartnerBranchState, itemVM.PartnerBranchPostCode);

            // Current status
            var currentStatus = item.LeadAssignmentStates.Where(w => w.StateId != nameof(EnumState.S0)).OrderByDescending(o => o.ActionTimestamp).FirstOrDefault();

            itemVM.StatusId   = currentStatus.State.Id;
            itemVM.StatusName = currentStatus.State.Name;
            itemVM.StatusTag  = StatusHelper.GetHtmlBadge(currentStatus.State.Id, currentStatus.State.Name);
            itemVM.RatingTag  = RatingHelper.GetHtmlRatingTag(item.Comment, item.CommentedBy, item.CommentedOn);

            if (string.IsNullOrEmpty(_userRoleName))
            {
                _userRoleName = _accountManager.GetRoleAsync(_accountManager.GetUserAsync(User.Identity.Name).Result).Result;
            }

            // Actions of current status
            var actions = currentStatus.State.StateActions.Where(w => this.IsActionAllowed(w.Action.Id, _userRoleName)).Select(s => new ActionLeadAssignmentVM
            {
                Id               = s.ActionId,
                LeadId           = itemVM.LeadId,
                PartnerBranchId  = itemVM.PartnerBranchId,
                LeadAssignmentId = itemVM.Id,
                CustomerEmail    = itemVM.CustomerEMail,
                PartnerEmails    = _salesRepo.GetByPartner(itemVM.PartnerId).Select(person => person.EMail).ToList(),
                ControllerName   = s.Action.ControllerName,
                ActionName       = s.Action.ActionName,
                ActionTarget     = s.Action.ActionTarget,
                RequestType      = s.Action.RequestType,
                DisplayName      = s.Action.DisplayName,
                Icon             = s.Action.Icon,
                NextStateId      = s.Action.NextStateId,
                Rating           = new Rating()
                {
                    Rate = item.Rate, Comment = item.Comment ?? string.Empty, CommentedOn = item.CommentedOn, CommentedBy = item.CommentedBy
                }
            }).ToList();

            itemVM.Actions = actions;

            // CreatedWhen
            var firstSssignedOn = item.LeadAssignmentStates.OrderBy(o => o.ActionTimestamp).FirstOrDefault();

            itemVM.AssignedOn = DateHelper.ConvertFromUtc(firstSssignedOn.ActionTimestamp).Date;

            // History
            var histories = item.LeadAssignmentStates
                            .OrderByDescending(o => o.ActionTimestamp)
                            //.Where(w => w.StateId != currentStatus.StateId) // *show all
                            .Select(s => HistoryHelper.GetHtmlHistoryLine(DateHelper.ConvertFromUtc(s.ActionTimestamp), s.Action.ToLower(), s.Actor));

            itemVM.History = HistoryHelper.GetHtmlHistoryTag(histories.ToList());

            return(itemVM);
        }