/// <summary>
        /// This function will update the tag as deleted in DB and wll de-associate modules
        /// </summary>
        /// <param name="tagId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool DeleteTag(int tagId, int userId)
        {
            Tag tag = new Tag();


            tag = tagRepository.SingleOrDefault(x => x.TagId == tagId);
            if (tag != null)
            {
                tag.RecordDeleted = true;
                tag.ModifiedBy    = userId;
                tag.ModifiedDate  = DateTime.Now;

                //Delete tag associated Accounts
                accountTagRepository.Delete(x => x.TagId == tag.TagId);
                //Delete tag associated Contacts
                contactTagRepository.Delete(x => x.TagId == tag.TagId);

                //Delete tag associatd with lead
                leadTagRepository.Delete(x => x.TagId == tag.TagId);

                //update tag in db as deleted
                tagRepository.Update(tag);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        //public IList<LeadModel> GetLeads(int companyId, int currentPage, int pageSize, ref int totalRecords)
        //{
        //    List<LeadModel> listLeadModel = new List<LeadModel>();
        //    List<Lead> listLeads = new List<Lead>();
        //    totalRecords = leadRepository.Count(x => x.CompanyId == companyId && x.RecordDeleted == false);
        //    listLeads = leadRepository.GetPagedRecords(x => x.CompanyId == companyId && x.RecordDeleted == false, y => y.Title, currentPage > 0 ? currentPage : 1, pageSize).ToList();
        //    AutoMapper.Mapper.Map(listLeads, listLeadModel);
        //    return listLeadModel;
        //}


        public void DeleteLead(LeadModel leadModel)
        {
            Lead lead = leadRepository.SingleOrDefault(where => where.LeadId == leadModel.LeadId && where.RecordDeleted == false);

            if (lead != null)
            {
                //De Associated lead Associated Quotes, products, Sales orders, Invoices & Tasks
                // De Associated lead Assiciated Quotes
                foreach (Quote objLeadQuote in lead.Quotes)
                {
                    objLeadQuote.LeadId = null;
                }

                // De Associated lead Assiciated Products
                foreach (ProductLeadAssociation objProductLeadAssociation in lead.ProductLeadAssociations)
                {
                    objProductLeadAssociation.LeadId = null;
                }

                // De Associated lead Associated SaleOrders
                //foreach (SalesOrder objLeadSalesOrder in lead.SalesOrders)
                //{
                //    objLeadSalesOrder.LeadId = null;

                //}

                // De Associated lead Associated invoice
                foreach (Invoice objLeadInvoice in lead.Invoices)
                {
                    objLeadInvoice.LeadId = null;
                }

                // De Associated lead Associated tasks
                List <TaskItem> listLeadTaskItems = taskItemRepository.GetAll(x => x.AssociatedModuleId == (int)ErucaCRM.Utility.Enums.Module.Lead && x.AssociatedModuleValue == leadModel.LeadId).ToList();

                foreach (TaskItem objTaskItems in listLeadTaskItems)
                {
                    objTaskItems.AssociatedModuleId    = null;
                    objTaskItems.AssociatedModuleValue = null;
                }
                taskItemRepository.UpdateAll(listLeadTaskItems);
                lead.RecordDeleted = true;
                lead.ModifiedBy    = leadModel.ModifiedBy;
                lead.ModifiedDate  = DateTime.UtcNow;
                leadRepository.Update(lead);
                AddLeadToDateAudit(lead, false);

                foreach (var leadtag in lead.LeadTags.ToList())
                {
                    //var checklead = leadTagRepository.SingleOrDefault(x => x.TagId == leadtag.TagId && x.LeadId != leadtag.LeadId);
                    //if (checklead == null)
                    //{

                    //    Tag tag = new Tag();
                    //    tag = tagRepository.SingleOrDefault(x => x.TagId == leadtag.TagId);
                    //    //tag.RecordDeleted = true;
                    //    tagRepository.Update(tag);
                    //}

                    leadTagRepository.Delete(x => x.LeadId == leadtag.LeadId && x.LeadTagId == leadtag.LeadTagId);
                }
            }
        }