public bool UpdateLeadDoc(LeadDocEntity leadDoc)
        {
            bool isDocUpdated = false;

            using (uow = new UnitOfWork.UnitOfWork())
            {
                try
                {
                    LeadDoc leaddocdb = uow.LeadDocRepository.Get().Where(x => x.LeadDocID == leadDoc.LeadDocID).FirstOrDefault();
                    leaddocdb.DocumentName = leadDoc.DocumentName;
                    leaddocdb.DocumentPath = leadDoc.DocumentPath;
                    leaddocdb.UploadDate   = leadDoc.UploadDate;
                    leaddocdb.UploadedBy   = leadDoc.UploadedBy;
                    leaddocdb.UploadedFor  = leadDoc.UploadedFor;
                    uow.LeadDocRepository.Update(leaddocdb);
                    uow.Save();
                    isDocUpdated = true;
                }
                catch
                {
                    isDocUpdated = false;
                }
            }

            return(isDocUpdated);
        }
        public int AddLeadDoc(LeadDocEntity leadDoc)
        {
            int docid = 0;

            using (uow = new UnitOfWork.UnitOfWork())
            {
                try
                {
                    LeadDoc leaddocdb = new LeadDoc();
                    leaddocdb.DocumentName = leadDoc.DocumentName;
                    leaddocdb.DocumentPath = leadDoc.DocumentPath;
                    leaddocdb.UploadDate   = leadDoc.UploadDate;
                    leaddocdb.UploadedBy   = leadDoc.UploadedBy;
                    leaddocdb.UploadedFor  = leadDoc.UploadedFor;
                    uow.LeadDocRepository.Insert(leaddocdb);
                    uow.Save();
                    docid = leaddocdb.LeadDocID;
                }
                catch
                {
                    docid = 0;
                }
            }

            return(docid);
        }
        public int CheckDoc(LeadDocEntity leadDoc)
        {
            int isDocAvailable = 0;

            using (uow = new UnitOfWork.UnitOfWork())
            {
                try
                {
                    isDocAvailable = uow.LeadDocRepository.Get().Where(x => x.UploadedFor == leadDoc.UploadedFor && x.UploadDate == leadDoc.UploadDate).Select(x => x.LeadDocID).FirstOrDefault();
                }
                catch
                {
                    isDocAvailable = 0;
                }
            }
            return(isDocAvailable);
        }
        protected void lstUsers_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "Upl")
            {
                FileUpload    fileUpl    = e.Item.FindControl("flUpload") as FileUpload;
                LeadDocEntity leadEntity = new LeadDocEntity();
                string        fileName   = DateTime.Now.ToString("yyyyMMddHHmmssfff") + fileUpl.FileName;
                leadEntity.DocumentName = fileUpl.FileName;
                leadEntity.DocumentPath = "Uploads/" + fileName;
                leadEntity.UploadedFor  = Convert.ToInt32(e.CommandArgument);
                leadEntity.UploadDate   = GetCurrentTime().ToShortDateString();
                leadEntity.UploadedBy   = Request.Cookies["Name"].Value;
                //int leadDocID = leadDocHelper.CheckDoc(leadEntity);
                int leadDocID = 0;
                if (leadDocID == 0)
                {
                    ListViewDataItem dataItem = (ListViewDataItem)e.Item;
                    fileUpl.SaveAs(Server.MapPath("~/Uploads/" + fileName));
                    int isuploaded = leadDocHelper.AddLeadDoc(leadEntity);
                    if (isuploaded > 0)
                    {
                        var excelName        = Server.MapPath("~/Uploads/" + fileName);
                        var connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelName + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";";

                        var adapter = new OleDbDataAdapter("SELECT * FROM [Leads$]", connectionString);
                        var ds      = new DataSet();

                        try
                        {
                            adapter.Fill(ds, "ExcelFileData");
                        }
                        catch (Exception ex)
                        {
                            Response.Write("<script>alert('" + ex.Message + "');</script>");
                        }

                        DataTable              data          = ds.Tables["ExcelFileData"];
                        List <DataRow>         list          = data.AsEnumerable().ToList();
                        List <DailyLeadEntity> listLeadsData = new List <DailyLeadEntity>();
                        foreach (DataRow item in list)
                        {
                            DailyLeadEntity saleData = new DailyLeadEntity();
                            saleData.AuthForHire     = item["AuthForHire"].ToString();
                            saleData.DateFiled       = item["DateFiled"].ToString();
                            saleData.DOTNumber       = item["DOTNumber"].ToString();
                            saleData.Drivers         = item["Drivers"].ToString();
                            saleData.Interstate      = item["Interstate"].ToString();
                            saleData.LeadDocID       = isuploaded;
                            saleData.LegalName       = item["LegalName"].ToString();
                            saleData.MailingAddress  = item["MailingAddress"].ToString();
                            saleData.OperatingStatus = item["OperatingStatus"].ToString();
                            saleData.PhoneNo         = item["PhoneNo"].ToString();
                            saleData.PhysicalAddress = item["PhysicalAddress"].ToString();
                            saleData.PowerUnits      = item["PowerUnits"].ToString();
                            saleData.Status          = "New Leads";
                            saleData.TimeZone        = item["TimeZone"].ToString();
                            saleData.ZipCode         = item["ZipCode"].ToString();
                            listLeadsData.Add(saleData);
                        }
                        dailyLeadsHelper.AddBulkLeads(listLeadsData);
                        // = list.Select(new DailyLeadEntity() { AuthForHire = list["AuthForHire"] }).ToList();
                        Response.Write("<script>alert('Lead uploaded Successfully.');</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('Some error occured.');</script>");
                    }
                }
                else
                {
                    leadEntity.LeadDocID = leadDocID;
                    fileUpl.SaveAs(Server.MapPath("~/Uploads/" + fileName));
                    leadDocHelper.UpdateLeadDoc(leadEntity);
                    Response.Write("<script>alert('Lead updated Successfully.');</script>");
                }
            }
        }