protected void btnSubmit_Click(object sender, EventArgs e)
    {
        List<DocRepository> lstDocs = new List<DocRepository>();
        UserRequest lstUserRequest = new UserRequest()
        {
            EmailId = txtEmailId.Text,
            FirstName = txtFirstName.Text,
            LastName = txtLastName.Text,
            Address1 = txtAddress1.Text,
            Address2 = txtAddress2.Text,
            ZipCode = Convert.ToInt32(txtZipCode.Text),
            CityName = txtCity.Text,
            StateId = Convert.ToInt32(ddlState.SelectedValue),
            PrimaryPhoneNo = txtPrimaryPhoneNumber.Text,
            PrimaryPhoneType = ddlPrimaryPhoneType.SelectedValue,
            PrimaryMobileProvider = ddlMobileProvider.SelectedValue,
            SecondaryPhoneNo = txtSecondaryPhoneNumber.Text,
            SecondaryPhoneType = ddlSecondaryPhoneType.SelectedValue,
            SecondaryMobileProvider = ddlSecondaryMobileProvider.SelectedValue,
            PrefContactMethod = ddlPrefContactMethod.SelectedValue,
            CreateDate = DateTime.UtcNow,
            ProblemLocation = txtProbLocation.Text,
            ShortDescription = txtShortDescProblem.Text,
            LongDescription = txtLongDescProblem.Text,
            EmailConfirmation = chkConfirm.Checked,
            AttachedDocName = null,
            Status = "O"
        };
        RequestStatus lstRequestStatus = new RequestStatus()
        {
            Status = "O",
            UpdateDate = DateTime.UtcNow
        };

        objBll = new WarringtonBll.WarringtonBll();
        if (chkOptLogin.Checked)
        {
            if (objBll.IsUserRegistered(txtPrimaryPhoneNumber.Text))
            {
                if (!Utility.GetSessionValue<bool>(Constants._USERISLOGGEDIN))
                {
                    Utility.SetSessionValue(Constants._REQUESTDATA, lstUserRequest);
                    Utility.SetSessionValue(Constants._REQUESTSTATUSDATA, lstRequestStatus);
                    Utility.SetSessionValue(Constants._REQUESTDOCS, lstDocs);
                    Utility.SetSessionValue(Constants._POSTEDFILES, fileUpload.PostedFiles);
                    Response.Redirect("Login.aspx?P=" + (int)PageEnum.RequestSubmissionPage);
                }
            }
            else
            {
                Utility.SetSessionValue(Constants._REQUESTDATA, lstUserRequest);
                Utility.SetSessionValue(Constants._REQUESTSTATUSDATA, lstRequestStatus);
                Utility.SetSessionValue(Constants._REQUESTDOCS, lstDocs);
                Utility.SetSessionValue(Constants._POSTEDFILES, fileUpload.PostedFiles);
                Response.Redirect("UserRegistration.aspx?D=1");
            }
        }
        IList<HttpPostedFile> postedFiles = null;
        if (fileUpload.HasFile)
        {
            postedFiles = fileUpload.PostedFiles;
        }
        else
        {
            postedFiles = Utility.GetSessionValue<IList<HttpPostedFile>>(Constants._POSTEDFILES);
        }
        foreach (HttpPostedFile  postedFile in postedFiles)
        {
            if (!string.IsNullOrEmpty(postedFile.FileName))
            {
                postedFile.SaveAs(Server.MapPath(@"~\DocRepository\") + postedFile.FileName);
                lstDocs.Add(new DocRepository()
                {
                    FileName = postedFile.FileName,
                    FilePath = Server.MapPath(@"~\DocRepository\"),
                    UploadDate = DateTime.UtcNow
                });
            }
        }
        bool isSaved = objBll.SaveUserRequest(lstUserRequest, lstRequestStatus, lstDocs);
        if (isSaved)
        {
            ClearControl();
            hdnFileName.Value = "";
            Utility.SetSessionValue(Constants._REQUESTDATA, null);
            Utility.SetSessionValue(Constants._REQUESTDOCS, null);
            Utility.SetSessionValue(Constants._POSTEDFILES,null);
            ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('User Request successfully submited...')", true);
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('There are some error...')", true);
        }
    }
        public bool SaveUserRequest(UserRequest requestData, RequestStatus statusData, List<DocRepository> documentData)
        {
            long requestId = 0;
            long statusId = 0; long docId = 0;
            using (var context = new TheThinkerz_WTPSharePointEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        tblUserRequest objUserRequest = new tblUserRequest();
                        var sql = "SELECT COUNT(1) FROM dbo.tblUserRequest where RequestId=" + requestData.RequestId;
                        var count = context.Database.SqlQuery<int>(sql).Single();
                        if (count == 0)
                        {
                            requestData.RequestNo = GenerateRequestNo();

                            objUserRequest.RequestNo = requestData.RequestNo;
                            objUserRequest.FirstName = requestData.FirstName;
                            objUserRequest.LastName = requestData.LastName;
                            objUserRequest.Address1 = requestData.Address1;
                            objUserRequest.Address2 = requestData.Address2;
                            objUserRequest.ZipCode = requestData.ZipCode;
                            objUserRequest.CityName = requestData.CityName;
                            objUserRequest.StateId = requestData.StateId;
                            objUserRequest.PrimaryPhoneNo = requestData.PrimaryPhoneNo;
                            objUserRequest.PrimaryPhoneType = requestData.PrimaryPhoneType;
                            objUserRequest.PrimaryMobileProvider = requestData.PrimaryMobileProvider;
                            objUserRequest.SecondaryPhoneNo = requestData.SecondaryPhoneNo;
                            objUserRequest.SecondaryPhoneType = requestData.SecondaryPhoneType;
                            objUserRequest.SecondaryMobileProvider = requestData.SecondaryMobileProvider;
                            objUserRequest.EmailId = requestData.EmailId;
                            objUserRequest.PrefContactMethod = requestData.PrefContactMethod;
                            objUserRequest.ProblemLocation = requestData.ProblemLocation;
                            objUserRequest.ShortDescription = requestData.ShortDescription;
                            objUserRequest.LongDescription = requestData.LongDescription;
                            objUserRequest.AttachedDocName = requestData.AttachedDocName;
                            objUserRequest.EmailConfirmation = requestData.EmailConfirmation;
                            objUserRequest.CreateDate = requestData.CreateDate;
                            objUserRequest.UpdateDate = requestData.UpdateDate;
                            objUserRequest.Status = requestData.Status;
                            context.tblUserRequests.Add(objUserRequest);
                        }
                        else
                        {
                            objUserRequest = context.tblUserRequests.Where(r => r.RequestId == requestData.RequestId).Single<tblUserRequest>(); ;
                            objUserRequest.ProblemLocation = requestData.ProblemLocation;
                            objUserRequest.ShortDescription = requestData.ShortDescription;
                            objUserRequest.LongDescription = requestData.LongDescription;
                            objUserRequest.EmailConfirmation = requestData.EmailConfirmation;
                            objUserRequest.Status = requestData.Status;
                            objUserRequest.UpdateDate = requestData.UpdateDate;

                        }

                        context.SaveChanges();
                        context.Entry(objUserRequest).GetDatabaseValues();
                        requestId = objUserRequest.RequestId;

                        tblDocRepository objDocRepository = new tblDocRepository();
                        foreach (DocRepository objItem in documentData)
                        {
                            objItem.RequestId = requestId;
                            var sqlDoc = "SELECT COUNT(1) FROM dbo.tblDocRepository where RecId=" + objItem.RecId;
                            var countDoc = context.Database.SqlQuery<int>(sqlDoc).Single();
                            if (countDoc == 0)
                            {
                                objDocRepository.RequestId = objItem.RequestId;
                                objDocRepository.FileName = objItem.FileName;
                                objDocRepository.FilePath = objItem.FilePath;
                                objDocRepository.UploadDate = objItem.UploadDate;

                                context.tblDocRepositories.Add(objDocRepository);
                                context.SaveChanges();
                            }
                            docId++;
                        }

                        tblRequestStatu objRequestStatus = new tblRequestStatu();

                        statusData.RequestId = requestId;
                        var sqlStatus = "SELECT COUNT(1) FROM dbo.tblRequestStatus where RecordId=" + statusData.RecordId;
                        var countStatus = context.Database.SqlQuery<int>(sqlStatus).Single();
                        if (countStatus == 0)
                        {
                            objRequestStatus.RequestId = statusData.RequestId;
                            objRequestStatus.Status = statusData.Status;
                            objRequestStatus.UpdateDate = statusData.UpdateDate;
                            objRequestStatus.UpdateBy = statusData.UpdateBy;

                            context.tblRequestStatus.Add(objRequestStatus);
                        }
                        context.SaveChanges();
                        if (statusData != null)
                        {
                            context.Entry(objRequestStatus).GetDatabaseValues();
                            statusId = objRequestStatus.RecordId;
                        }
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }
            return requestId > 0 && statusId > 0 && documentData.Count == docId;
        }
        public bool SaveUserRequest(UserRequest requestData, RequestStatus statusData, List<DocRepository> documentData)
        {
            long userId = 0;
            bool isSaved = false;
            try
            {
                objDal = new WarringtonDal();
                isSaved = objDal.SaveUserRequest(requestData, statusData, documentData);
                if (isSaved)
                {
                    List<LoginHistory> lstLoginHistory = new List<LoginHistory>();
                    lstLoginHistory.Add(new LoginHistory()
                    {
                        UserId = userId,
                        ClientIp = Utility.GetLanIPAddress(),
                        Activity = "Request submission Process done",
                        EntryDate = DateTime.UtcNow
                    });

                    return objDal.SaveLoginHistory(lstLoginHistory) > 0;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                objDal = null;
            }
            return false;
        }
    protected void btnSendRequest_Click(object sender, EventArgs e)
    {
        objBll = new WarringtonBll.WarringtonBll();
        List<DocRepository> lstDocs = new List<DocRepository>();
        UserRequest lstUserRequest = new UserRequest()
        {
            RequestId=Convert.ToInt32(hdnReqId.Value),
            CreateDate = DateTime.UtcNow,
            ProblemLocation = txtAddress.Text,
            ShortDescription = txtShortDesc.Text,
            LongDescription = txtLongDesc.Text,
            EmailConfirmation = chkConfirmEmail.Checked,
            Status = "U",
            UpdateDate=DateTime.UtcNow
        };
        RequestStatus lstRequestStatus = new RequestStatus()
        {
            Status = "U",
            UpdateDate = DateTime.UtcNow
        };
        IList<HttpPostedFile> postedFiles = null;
        if (fuploadDocs.HasFile)
        {
            postedFiles = fuploadDocs.PostedFiles;

            foreach (HttpPostedFile postedFile in postedFiles)
            {
                if (!string.IsNullOrEmpty(postedFile.FileName))
                {
                    postedFile.SaveAs(Server.MapPath(@"~\DocRepository\") + postedFile.FileName);
                    lstDocs.Add(new DocRepository()
                    {
                        FileName = postedFile.FileName,
                        FilePath = Server.MapPath(@"~\DocRepository\"),
                        UploadDate = DateTime.UtcNow
                    });
                }
            }
        }
        bool isSaved = objBll.SaveUserRequest(lstUserRequest, lstRequestStatus, lstDocs);
        if (isSaved)
        {
            ClearControl();
            hdnFileList.Value = "";
            BindSearchGrid();
            pnlEdit.Visible = false;
            ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('User Request successfully submited...')", true);
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('There are some error...')", true);
        }
    }