protected void Button1_Click(object sender, EventArgs e)
 {
     List<LoginHistory> data = new List<LoginHistory>();
     data.Add(new LoginHistory() {UserId=1,ClientIp=HttpContext.Current.Request.UserHostAddress,Activity="Surfing",EntryDate=DateTime.Now });
     WarringtonBll.WarringtonBll objBll = new WarringtonBll.WarringtonBll();
     objBll.SaveLoginHistory(data);
 }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        objBll = new WarringtonBll.WarringtonBll();
        if (chkAgreePolicy.Checked)
        {
            if (!objBll.CheckPhoneNoExit(txtPrimaryPhoneNumber.Text))
            {
                List<UserMaster> lstUser = new List<UserMaster>();
                lstUser.Add(new UserMaster()
                {
                    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,
                    PrefferedContactMethod = ddlPrefContactMethod.SelectedValue,
                    CreateDate = DateTime.UtcNow,
                    PinNo = txtPin.Text,
                    Active = true
                });

                bool isSaved = objBll.SaveUserMaster(lstUser);
                if (isSaved)
                {
                    ClearControl();
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('User Registration successfully done...')", true);
                    Response.Redirect("Login.aspx?P=" + (int)PageEnum.RequestSubmissionPage);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('There are some error...')", true);
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('Primary Phone no must be unique. Duplicate Phone no found.')", true);
            }
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('Please confirm that you are accepting the privacy rules...')", true);
        }
    }
    public void BindSearchGrid()
    {
        objBll = new WarringtonBll.WarringtonBll();
        SearchParam objSearchParam = new SearchParam()
        {
            UserId = Utility.GetSessionValue<string>(Constants._LOGINUSERID),
            RequestStatus = txtStatus.Text,
            RequestNo = txtRequestNo.Text,
            RequestDate = string.IsNullOrEmpty(txtRequestDate.Text) ? DateTime.MinValue :
            DateTime.ParseExact(txtRequestDate.Text, "MM/dd/yyyy", null),
            CompareOperator=ddlOperator.SelectedValue,
            NoOfData=Convert.ToInt32(ddlPageSize.SelectedValue)
        };
        List<UserRequest> lstRequest = objBll.SearchRequest(objSearchParam);
        DataTable dtSearchResult = new DataTable();
        dtSearchResult.Columns.Add("Request_No");
        dtSearchResult.Columns.Add("Request_ID");
        dtSearchResult.Columns.Add("Request_Date");
        dtSearchResult.Columns.Add("Request_ChangeDate");
        dtSearchResult.Columns.Add("Request_Status");
        dtSearchResult.Columns.Add("Request_Address");
        dtSearchResult.Columns.Add("Request_ShortDesc");
        dtSearchResult.Columns.Add("Request_LongDesc");

        foreach (UserRequest  objrequest in lstRequest)
        {
            DataRow drRequest = dtSearchResult.NewRow();
            drRequest["Request_No"] = objrequest.RequestNo;
            drRequest["Request_ID"] = objrequest.RequestId;
            drRequest["Request_Date"] = objrequest.CreateDate.Value.Date.ToShortDateString();
            drRequest["Request_ChangeDate"] = objrequest.UpdateDate!=null?objrequest.UpdateDate.Value.Date.ToShortDateString():null;
            drRequest["Request_Status"] = objrequest.Status.Trim().Equals("O")?"Open":"Closed";
            drRequest["Request_Address"] = objrequest.ProblemLocation;
            drRequest["Request_ShortDesc"] = objrequest.ShortDescription;
            drRequest["Request_LongDesc"] = objrequest.LongDescription;
            dtSearchResult.Rows.Add(drRequest);
        }
        dtSearchResult.AcceptChanges();
        grdRequests.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
        if (!dtSearchResult.DataTableIsEmpty())
        {
            Utility.SetSessionValue(Constants._SEARCHREQUESTDATA, dtSearchResult);
            grdRequests.DataSource = dtSearchResult;
            grdRequests.DataBind();
        }
        else
        {
            grdRequests.Dispose();
            grdRequests.DataBind();
        }
    }
 private void btnLogin_Click(object sender, EventArgs e)
 {
     string userId = string.Empty;
     objBll = new WarringtonBll.WarringtonBll();
     if (objBll.UserIsAuthenticated(txtUserId.Text.Trim(), txtPassword.Text.Trim(), out userId))
     {
         Utility.SetSessionValue(Constants._USERISLOGGEDIN, true);
         Utility.SetSessionValue(Constants._LOGINUSERID, userId);
         Response.Redirect(GetPageName());
     }
     else
     {
         ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('The Phone no and Pin you entered don't match. User authentication fails..')", true);
     }
 }
    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);
        }
    }
 protected void BindStates()
 {
     WarringtonBll.WarringtonBll objBll = new WarringtonBll.WarringtonBll();
     List<StateMaster> lstStates = objBll.GetStateData();
     Utility.BindDropDownList<StateMaster>(lstStates, ddlState, "Select State", 1, 0);
 }
    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);
        }
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        objBll = new WarringtonBll.WarringtonBll();
        pnlEdit.Visible = true;

        Button btnUpdate = (Button)sender;
        GridViewRow gvr = (GridViewRow)btnUpdate.NamingContainer;
        var hdnRequestId = (HiddenField)gvr.FindControl("hdnRequestId");
        var lblProbAddress = (Label)gvr.FindControl("lblProbAddress");
        var lblShortDesc = (Label)gvr.FindControl("lblShortDesc");
        var lblLongDesc = (Label)gvr.FindControl("lblLongDesc");

        hdnReqId.Value = hdnRequestId.Value;
        hdnFileList.Value = objBll.GetUploadedFiles(Convert.ToInt32(hdnRequestId.Value));
        txtAddress.Text = lblProbAddress.Text;
        txtShortDesc.Text = lblShortDesc.Text;
        txtLongDesc.Text = lblLongDesc.Text;
    }