public void DeleteUploadLead(int?UploadLeadId, string username)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    DeleteUploadLeadDetailData(UploadLeadId);
                    kkslm_tr_upload_lead rd = slmdb.kkslm_tr_upload_lead.Where(r => r.slm_UploadLeadId == UploadLeadId).FirstOrDefault();

                    // slmdb.kkslm_tr_upload_lead.DeleteObject(rd);
                    rd.Is_Deleted      = 1;
                    rd.slm_UpdatedBy   = username;
                    rd.slm_UpdatedDate = DateTime.Now;
                    slmdb.SaveChanges();

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void EditUploadLead(UploadLeadData UploadLead, List <UploadLeadDetailData> UploadLeadDetailData, string username)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    kkslm_tr_upload_lead rk = slmdb.kkslm_tr_upload_lead.Where(r => r.slm_UploadLeadId == UploadLead.slm_UploadLeadId).FirstOrDefault();


                    rk.slm_LeadCount = UploadLead.slm_LeadCount;
                    //rk.Status = UploadLead.Status;
                    //rk.AssignedDate = UploadLead.AssignedDate;
                    rk.slm_CampaignCode = UploadLead.slm_CampaignCode;

                    rk.slm_UpdatedBy   = username;
                    rk.slm_UpdatedDate = DateTime.Now;



                    //slmdb.UploadLead.AddObject(rk);
                    slmdb.SaveChanges();


                    //delete old UploadLead_Campaign
                    List <kkslm_tr_upload_lead_detail> oldUploadLeadDetail = slmdb.kkslm_tr_upload_lead_detail.Where(r => r.slm_UploadLeadId == UploadLead.slm_UploadLeadId).ToList();

                    if (oldUploadLeadDetail != null)
                    {
                        foreach (kkslm_tr_upload_lead_detail orc in oldUploadLeadDetail)
                        {
                            slmdb.kkslm_tr_upload_lead_detail.DeleteObject(orc);
                            slmdb.SaveChanges();
                        }
                    }



                    //add UploadLeadcampaigns
                    if (UploadLeadDetailData != null)
                    {
                        foreach (UploadLeadDetailData rcd in UploadLeadDetailData)
                        {
                            //if (slmdb.UploadLeadDetail.Where(r => r.CampaignCode == rcd.CampaignCode && r.CampaignCode == rcd.CampaignName).Count() == 0)
                            //{
                            kkslm_tr_upload_lead_detail rc = new kkslm_tr_upload_lead_detail();

                            rc.slm_UploadLeadId        = rcd.slm_UploadLeadId;
                            rc.slm_ContractBranchName  = rcd.slm_ContractBranchName;
                            rc.slm_OwnerLead           = rcd.slm_OwnerLead;
                            rc.slm_ThaiFirstName       = rcd.slm_ThaiFirstName;
                            rc.slm_ThaiLastName        = rcd.slm_ThaiLastName;
                            rc.slm_CardIdType          = rcd.slm_CardIdType;
                            rc.slm_CardId              = rcd.slm_CardId;
                            rc.slm_CustTelephoneMobile = rcd.slm_CustTelephoneMobile;
                            rc.slm_CustTelephoneHome   = rcd.slm_CustTelephoneHome;
                            rc.slm_CustTelephoneOther  = rcd.slm_CustTelephoneOther;
                            rc.slm_BrandName           = rcd.slm_BrandName;
                            rc.slm_ModelName           = rcd.slm_ModelName;
                            rc.slm_ModelYear           = rcd.slm_ModelYear;
                            rc.slm_HpBscodeXsell       = rcd.slm_HpBscodeXsell;
                            rc.slm_Remark              = rcd.slm_Remark;
                            rc.slm_TicketID            = rcd.slm_TicketID;

                            slmdb.kkslm_tr_upload_lead_detail.AddObject(rc);
                            slmdb.SaveChanges();
                            //}
                        }
                    }



                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }