Exemplo n.º 1
0
        void ILeadAuditBusiness.Update(LeadAuditModel leadAuditModel)
        {
            LeadAudit leadAudit = new LeadAudit();

            leadAudit = leadAuditRepository.GetAll(c => c.LeadId == leadAuditModel.LeadId).LastOrDefault();
            AutoMapper.Mapper.Map(leadAuditModel, leadAudit);
            leadAuditRepository.Update(leadAudit);
        }
Exemplo n.º 2
0
        public LeadAuditModel GetLeadAuditByLeadId(int LeadId)
        {
            LeadAudit      leadAudit      = new LeadAudit();
            LeadAuditModel leadAuditModel = new LeadAuditModel();

            leadAudit = leadAuditRepository.GetAll().Where(c => c.LeadId == LeadId).OrderBy(x => x.LeadAuditId).LastOrDefault();
            AutoMapper.Mapper.Map(leadAudit, leadAuditModel);
            return(leadAuditModel);
        }
Exemplo n.º 3
0
        void ILeadAuditBusiness.Add(LeadAuditModel leadAuditModel)
        {
            LeadAudit leadAudit = new LeadAudit();

            AutoMapper.Mapper.Map(leadAuditModel, leadAudit);

            if (leadAudit.RatingId == 0)
            {
                leadAudit.RatingId = null;
            }

            leadAuditRepository.Insert(leadAudit);
        }
Exemplo n.º 4
0
        private void AddLeadToDateAudit(Lead lead, bool islastStage = false)
        {
            LeadAuditModel leadAuditModel = new LeadAuditModel();

            leadAuditModel = leadAuditBusiness.GetLeadAuditByLeadId(lead.LeadId);
            if (leadAuditModel.LeadId != null)
            {
                if (lead.RecordDeleted == true)
                {
                    leadAuditModel.CreatedBy    = lead.ModifiedBy;
                    leadAuditModel.ActivityType = (int)Enums.ActivityType.LeadDeleted;
                    leadAuditModel.ClosingDate  = DateTime.UtcNow;
                    leadAuditModel.ToDate       = DateTime.UtcNow;
                }
                else if (lead.StageId != leadAuditModel.StageId && lead.StageId != null)
                {
                    leadAuditModel.ToDate = DateTime.UtcNow;
                    leadAuditBusiness.Update(leadAuditModel);
                    AutoMapper.Mapper.Map(lead, leadAuditModel);
                    leadAuditModel.ToDate       = null;
                    leadAuditModel.CreatedBy    = lead.ModifiedBy;
                    leadAuditModel.ActivityType = (int)Enums.ActivityType.LeadStageChanged;
                    if (islastStage)
                    {
                        leadAuditModel.ClosingDate = DateTime.UtcNow;
                    }
                    leadAuditModel.FromDate = DateTime.UtcNow;
                }
                else if (lead.RatingId != leadAuditModel.RatingId || lead.Amount != leadAuditModel.Amount)
                {
                    if (lead.RatingId != leadAuditModel.RatingId && lead.RatingId != null && lead.RatingId != 0)
                    {
                        leadAuditModel.ActivityType = (int)Enums.ActivityType.LeadRatingChanged;
                    }
                    else if (lead.Amount != leadAuditModel.Amount && lead.Amount != null)
                    {
                        leadAuditModel.ActivityType = (int)Enums.ActivityType.LeadAmountChanged;
                    }
                    AutoMapper.Mapper.Map(lead, leadAuditModel);
                    leadAuditModel.CreatedBy = lead.ModifiedBy;
                }
            }
            else
            {
                AutoMapper.Mapper.Map(lead, leadAuditModel);
                leadAuditModel.ActivityType = (int)Enums.ActivityType.LeadAdded;
                leadAuditModel.FromDate     = DateTime.UtcNow;
            }
            leadAuditModel.CreatedDate = DateTime.UtcNow;
            leadAuditBusiness.Add(leadAuditModel);
        }
Exemplo n.º 5
0
        public LeadModel UpdateLead(LeadModel leadModel)
        {
            LeadAuditModel leadAuditModel = new LeadAuditModel();

            if (!leadModel.LeadSourceId.HasValue || leadModel.LeadSourceId.Value == 0)
            {
                leadModel.LeadSourceId    = null;
                leadModel.LeadSourceModel = null;
            }
            if (!leadModel.LeadStatusId.HasValue || leadModel.LeadStatusId.Value == 0)
            {
                leadModel.LeadStatusId    = null;
                leadModel.LeadStatusModel = null;
            }
            if (!leadModel.IndustryId.HasValue || leadModel.IndustryId.Value == 0)
            {
                leadModel.IndustryId    = null;
                leadModel.IndustryModel = null;
            }

            Lead lead         = leadRepository.SingleOrDefault(x => x.LeadId == leadModel.LeadId && x.RecordDeleted == false);
            Lead leadForAudit = new Lead();

            if ((lead.ClosingDate.HasValue && lead.ClosingDate != leadModel.ClosingDate)
                ||
                (lead.Amount.HasValue && lead.Amount != leadModel.Amount) || (lead.Amount == null && leadModel.Amount.HasValue)
                )
            {
                AutoMapper.Mapper.Map(leadModel, leadForAudit);
                leadForAudit.StageId   = lead.StageId;
                leadForAudit.CreatedBy = leadModel.ModifiedBy;

                AddLeadToDateAudit(leadForAudit, false);
            }
            if (!leadModel.LeadOwnerId.HasValue || leadModel.LeadOwnerId == 0)
            {
                leadModel.LeadOwnerId = lead.LeadOwnerId;
            }
            leadModel.CompanyId   = lead.CompanyId;
            leadModel.StageId     = leadModel.StageId == null || leadModel.StageId == 0 ? lead.StageId : leadModel.StageId;
            leadModel.CreatedBy   = leadModel.CreatedBy == null ? lead.CreatedBy : leadModel.CreatedBy;
            leadModel.CreatedDate = lead.CreatedDate;
            AutoMapper.Mapper.Map(leadModel, lead);
            lead.RatingId = leadModel.RatingId > 0 ? leadModel.RatingId : null;
            lead.Address  = ValidateAddress(lead.Address, leadModel.AddressModel);
            //if (lead.ContactId == 0)
            lead.ModifiedDate = DateTime.UtcNow;
            leadRepository.Update(lead);
            lead = leadRepository.SingleOrDefault(x => x.LeadId == lead.LeadId && x.RecordDeleted == false);
            AutoMapper.Mapper.Map(lead, leadModel);
            //Tag Association

            List <int> listAllExistingTagIds       = new List <int>();
            List <int> listNewTagIds               = new List <int>();
            List <int> listContactAssociatedTagIds = new List <int>();
            List <int> listDeleteTagIds            = new List <int>();

            listContactAssociatedTagIds = lead.LeadTags.Select(x => x.TagId).ToList();

            if (!string.IsNullOrEmpty(leadModel.LeadTagIds))
            {
                string[] arrTagIds = leadModel.LeadTagIds.Split(',');
                for (int i = 0; i < arrTagIds.Length; i++)
                {
                    int tagId = arrTagIds[i].Decrypt();

                    if (listContactAssociatedTagIds.Where(x => x == tagId).Count() == 0)
                    {
                        listNewTagIds.Add(tagId);
                    }
                    else
                    {
                        listAllExistingTagIds.Add(tagId);
                    }
                }
            }


            if (!string.IsNullOrEmpty(leadModel.NewTagNames))
            {
                List <int> lisNewAddedTagIds = new List <int>();
                lisNewAddedTagIds = AddTagsToSystem(leadModel.NewTagNames, leadModel.CompanyId.Value, leadModel.CreatedBy.Value);

                if (lisNewAddedTagIds.Count > 0)
                {
                    listNewTagIds = listNewTagIds.Concat(lisNewAddedTagIds).ToList();
                }
            }
            for (int i = 0; i < listContactAssociatedTagIds.Count; i++)
            {
                if (listAllExistingTagIds.Where(x => x == listContactAssociatedTagIds[i]).Count() == 0)
                {
                    listDeleteTagIds.Add(listContactAssociatedTagIds[i]);
                }
            }

            //Associate Tagids to contact
            if (listNewTagIds.Count > 0)
            {
                LeadTag leadTag;
                for (int i = 0; i < listNewTagIds.Count; i++)
                {
                    leadTag        = new LeadTag();
                    leadTag.LeadId = lead.LeadId;
                    leadTag.TagId  = listNewTagIds[i];
                    leadTagRepository.Insert(leadTag);
                }
            }

            if (listDeleteTagIds.Count > 0)
            {
                leadTagRepository.Delete(x => x.LeadId == lead.LeadId && listDeleteTagIds.Contains(x.TagId));
            }

            return(leadModel);
        }