public bool UpdateStatus(int LeadId, string GroupId)
        {
            bool                  status           = false;
            SALES_tblLeads        objlead          = new SALES_tblLeads();
            SALES_tblLeadTracking objsalestracking = new SALES_tblLeadTracking();

            using (var context = new CommonDBContext())
            {
                objlead             = context.SALES_tblLeads.Where(x => x.LeadId == LeadId).FirstOrDefault();
                objlead.UpdatedDate = DateTime.Now;
                objlead.MeetingType = "salesdone";
                objlead.GroupId     = GroupId;
                context.SALES_tblLeads.AddOrUpdate(objlead);
                context.SaveChanges();

                objsalestracking.LeadId      = objlead.LeadId;
                objsalestracking.ContactType = objlead.ContactType;
                objsalestracking.SpokeWith   = objlead.SpokeWith;
                objsalestracking.LeadStatus  = objlead.LeadStatus;
                objsalestracking.MeetingType = "salesdone";

                objsalestracking.FollowupDate     = objlead.FollowupDate;
                objsalestracking.BillingPartner   = objlead.BillingPartner;
                objsalestracking.NoOfOutlet       = objlead.NoOfOutlet;
                objsalestracking.EcomIntegration  = objlead.EcomIntegration;
                objsalestracking.Address          = objlead.Address;
                objsalestracking.State            = objlead.State;
                objsalestracking.AlternateNo      = objlead.AlternateNo;
                objsalestracking.EmailId          = objlead.EmailId;
                objsalestracking.AuthorizedPerson = objlead.AuthorizedPerson;
                objsalestracking.APMobileNo       = objlead.APMobileNo;
                objsalestracking.PriceQuoted      = objlead.PriceQuoted;
                objsalestracking.LeadSource       = objlead.LeadSource;
                objsalestracking.LeadSourceName   = objlead.LeadSourceName;
                objsalestracking.Comments         = objlead.Comments;
                objsalestracking.AddedBy          = objlead.AddedBy;
                objsalestracking.AddedDate        = DateTime.Now;

                context.SALES_tblLeadTracking.AddOrUpdate(objsalestracking);
                context.SaveChanges();
                status = true;
            }

            return(status);
        }
        public bool LeadTransfer(int[] LeadId, string SaleManagerId, string addedby)
        {
            bool result = false;

            try
            {
                SALES_tblLeads        objsaleslead         = new SALES_tblLeads();
                SALES_tblLeadTracking objsalesleadtracking = new SALES_tblLeadTracking();
                // string connStr = objCustRepo.GetCustomerConnString(GroupId);
                using (var contextNew = new CommonDBContext())
                {
                    foreach (int leadid in LeadId)
                    {
                        if (leadid != 0)
                        {
                            objsaleslead = contextNew.SALES_tblLeads.Where(x => x.LeadId == leadid).FirstOrDefault();
                            objsaleslead.AssignedLead = SaleManagerId;
                            objsaleslead.UpdatedDate  = DateTime.Now;
                            contextNew.SALES_tblLeads.AddOrUpdate(objsaleslead);
                            contextNew.SaveChanges();
                            objsalesleadtracking = contextNew.SALES_tblLeadTracking.Where(x => x.LeadId == leadid).FirstOrDefault();
                            if (objsalesleadtracking != null)
                            {
                                objsalesleadtracking.AssignedLead = SaleManagerId;
                                objsalesleadtracking.AddedBy      = addedby;
                                objsalesleadtracking.AddedDate    = DateTime.Now;
                                contextNew.SALES_tblLeadTracking.AddOrUpdate(objsalesleadtracking);
                                contextNew.SaveChanges();
                            }
                            result = true;
                        }
                    }
                    //}
                }
            }
            catch (Exception ex)
            {
                newexception.AddException(ex, "LeadTransfer");
            }
            return(result);
        }
        public int AddSalesLead(SALES_tblLeads objtbllead)
        {
            SALES_tblLeads        objlead          = new SALES_tblLeads();
            SALES_tblLeadTracking objsalestracking = new SALES_tblLeadTracking();
            int leadId = 0;

            using (var context = new CommonDBContext())
            {
                if (objtbllead.LeadId == 0)
                {
                    context.SALES_tblLeads.Add(objtbllead);
                    context.SaveChanges();
                    leadId = objtbllead.LeadId;

                    objsalestracking.LeadId           = objtbllead.LeadId;
                    objsalestracking.ContactType      = objtbllead.ContactType;
                    objsalestracking.SpokeWith        = objtbllead.SpokeWith;
                    objsalestracking.LeadStatus       = objtbllead.LeadStatus;
                    objsalestracking.MeetingType      = objtbllead.MeetingType;
                    objsalestracking.FollowupDate     = objtbllead.FollowupDate;
                    objsalestracking.BillingPartner   = objtbllead.BillingPartner;
                    objsalestracking.NoOfOutlet       = objtbllead.NoOfOutlet;
                    objsalestracking.EcomIntegration  = objtbllead.EcomIntegration;
                    objsalestracking.Address          = objtbllead.Address;
                    objsalestracking.State            = objtbllead.State;
                    objsalestracking.AlternateNo      = objtbllead.AlternateNo;
                    objsalestracking.EmailId          = objtbllead.EmailId;
                    objsalestracking.AuthorizedPerson = objtbllead.AuthorizedPerson;
                    objsalestracking.APMobileNo       = objtbllead.APMobileNo;
                    objsalestracking.PriceQuoted      = objtbllead.PriceQuoted;
                    objsalestracking.LeadSource       = objtbllead.LeadSource;
                    objsalestracking.LeadSourceName   = objtbllead.LeadSourceName;
                    objsalestracking.Comments         = objtbllead.Comments;
                    objsalestracking.AddedBy          = objtbllead.AddedBy;
                    objsalestracking.AddedDate        = objtbllead.AddedDate;
                    objsalestracking.AssignedLead     = objtbllead.AddedBy;

                    context.SALES_tblLeadTracking.AddOrUpdate(objsalestracking);
                    context.SaveChanges();
                }
                else
                {
                    objlead = context.SALES_tblLeads.Where(x => x.LeadId == objtbllead.LeadId).FirstOrDefault();

                    objtbllead.UpdatedDate = DateTime.Now;
                    objtbllead.Category    = objlead.Category;
                    objtbllead.Product     = objlead.Product;
                    objtbllead.City        = objlead.City;

                    if (objtbllead.MeetingType == "salesdone")
                    {
                        objtbllead.MeetingType = objlead.MeetingType;
                    }

                    context.SALES_tblLeads.AddOrUpdate(objtbllead);
                    context.SaveChanges();
                    //leadId = objtbllead.LeadId;

                    objsalestracking.LeadId      = objlead.LeadId;
                    objsalestracking.ContactType = objtbllead.ContactType;
                    objsalestracking.SpokeWith   = objtbllead.SpokeWith;
                    objsalestracking.LeadStatus  = objtbllead.LeadStatus;
                    if (objtbllead.MeetingType == "salesdone")
                    {
                        objsalestracking.MeetingType = objlead.MeetingType;
                    }
                    else
                    {
                        objsalestracking.MeetingType = objtbllead.MeetingType;
                    }
                    objsalestracking.FollowupDate     = objtbllead.FollowupDate;
                    objsalestracking.BillingPartner   = objtbllead.BillingPartner;
                    objsalestracking.NoOfOutlet       = objtbllead.NoOfOutlet;
                    objsalestracking.EcomIntegration  = objtbllead.EcomIntegration;
                    objsalestracking.Address          = objtbllead.Address;
                    objsalestracking.State            = objtbllead.State;
                    objsalestracking.AlternateNo      = objtbllead.AlternateNo;
                    objsalestracking.EmailId          = objtbllead.EmailId;
                    objsalestracking.AuthorizedPerson = objtbllead.AuthorizedPerson;
                    objsalestracking.APMobileNo       = objtbllead.APMobileNo;
                    objsalestracking.PriceQuoted      = objtbllead.PriceQuoted;
                    objsalestracking.LeadSource       = objtbllead.LeadSource;
                    objsalestracking.LeadSourceName   = objtbllead.LeadSourceName;
                    objsalestracking.Comments         = objtbllead.Comments;
                    objsalestracking.AddedBy          = objtbllead.AddedBy;
                    objsalestracking.AddedDate        = objtbllead.AddedDate;
                    objsalestracking.AssignedLead     = objtbllead.AddedBy;

                    context.SALES_tblLeadTracking.AddOrUpdate(objsalestracking);
                    context.SaveChanges();

                    leadId = objtbllead.LeadId;
                }
            }
            return(leadId);
        }