public void SetState(int assignmentId, EnumState state, EnumStateActionTaken action, string userName) { var itemState = new LeadAssignmentState { LeadAssignmentId = assignmentId, StateId = state.ToString(), Actor = userName, Action = action.ToString(), ActionTimestamp = DateHelper.Now }; _context.LeadAssignmentStates.Add(itemState); }
private List <ReportInvoiceVM> GetReportInvoiceVMs(IEnumerable <Lead> leads, List <int> leadAssignmentIds = null) { List <ReportInvoiceVM> reportInvoiceVMs = new List <ReportInvoiceVM>(); if (leads != null) { foreach (var lead in leads) { var submittedState = lead.LeadStates.OrderBy(o => o.ActionTimestamp).FirstOrDefault(); List <LeadAssignment> invoicableAssignments = new List <LeadAssignment>(); LeadAssignmentState assignedState = null, acceptedState = null, assignmentCurrentState = null; StateAction invoiceAction = null; var leadAssignments = leadAssignmentIds != null?lead.LeadAssignments.Where(w => leadAssignmentIds.Contains(w.Id)) : lead.LeadAssignments; foreach (var assignment in leadAssignments) { assignedState = assignment.LeadAssignmentStates .OrderBy(o => o.ActionTimestamp).FirstOrDefault(); acceptedState = assignment.LeadAssignmentStates .Where(w => w.StateId == nameof(EnumState.SLA2)) .OrderByDescending(o => o.ActionTimestamp).FirstOrDefault(); assignmentCurrentState = assignment.LeadAssignmentStates.Where(w => w.StateId != nameof(EnumState.S0)) .OrderByDescending(o => o.ActionTimestamp).FirstOrDefault(); invoiceAction = assignmentCurrentState.State.StateActions.Where(w => INVOICABLE_ACTIONS.Contains(w.ActionId)).FirstOrDefault(); if (invoiceAction != null) { var reportInvoiceVM = this.GetReportInvoiceVM(lead, assignment, submittedState, assignedState, acceptedState, assignmentCurrentState, invoiceAction); reportInvoiceVMs.Add(reportInvoiceVM); } } } } return(reportInvoiceVMs); }
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 }); }