protected void ApproveButton_Click(object sender, EventArgs e)
        {
            try
            {
                string approvedBy = (string)Global.SessionUser.UserName;
                tinRequest = (ITINRequest)Session["TinRequest"];
                long requestId = tinRequest.RequestId;

                string tin = ITINRequest.ApproveTinRequest(requestId, approvedBy);

                string message = string.Format("TIN: {0} has been successfully generated.", tin);
                DisplayAlert("Success", "Individual TIN Request", message);

                string firstName = tinRequest.FirstName;
                string lastname  = tinRequest.LastName;
                string phone     = tinRequest.Phone1;

                //SMSMessaging.SendGenericSms(firstName,lastname,tin,phone);

                TinRequestGridview.DataBind();
                TinRequestMultiView.ActiveViewIndex = 0;
            }
            catch (Exception ex)
            {
                DisplayAlert("Danger", "Individual TIN Request", ex.Message);
            }
        }
        protected void RequestIdButton_Click(object sender, EventArgs e)
        {
            ViewState["IsNewRecord"] = false;

            ASPxButton btn = (ASPxButton)sender;
            GridViewDataItemTemplateContainer container = (GridViewDataItemTemplateContainer)btn.NamingContainer;
            var value = container.Grid.GetRowValues(container.VisibleIndex, new string[] { "RequestId" });

            long requestId = (long)value;

            try
            {
                tinRequest = context.ITINRequests.Single(r => r.RequestId == requestId);
                context.Entry(tinRequest).Reload();

                OriginLgaCombo_Callback(new object(), new CallbackEventArgsBase(tinRequest.OriginStateId));
                AddressLgaCombo_Callback(new object(), new CallbackEventArgsBase(tinRequest.AddressStateId));

                TinRequestForm.DataSource = tinRequest;
                TinRequestForm.DataBind();

                Session["TinRequest"] = tinRequest;

                TinRequestMultiView.ActiveViewIndex = 1;
                SetButtonVisibility();
            }
            catch (Exception ex)
            {
                DisplayAlert("Danger", "Get Individual Taxpayer", ex.Message);
                return;
            }
        }
        private void SetButtonVisibility()
        {
            if ((Boolean)ViewState["IsNewRecord"] == true)
            {
                TinRequestForm.ForEach(ClearItem);
                TinRequestForm.ForEach(EnableItem);

                TinRequestForm.Enabled = true;
                SubmitButton.Visible   = true;
                ApproveButton.Visible  = false;
                RejectButton.Visible   = false;
            }
            else
            {
                tinRequest = (Model.ITINRequest)Session["TinRequest"];
                // check request status;
                switch (tinRequest.Status)
                {
                case "Submitted":
                    TinRequestForm.ForEach(DisableItem);
                    SubmitButton.Visible  = false;
                    ApproveButton.Visible = Global.SessionUser.RoleId == 1 ? true : false;
                    RejectButton.Visible  = Global.SessionUser.RoleId == 1 ? true : false;
                    break;

                case "Approved":
                    TinRequestForm.ForEach(DisableItem);
                    SubmitButton.Visible  = false;
                    ApproveButton.Visible = false;
                    RejectButton.Visible  = false;
                    break;

                case "Rejected":
                    TinRequestForm.Enabled = true;
                    TinRequestForm.ForEach(EnableItem);

                    if (Global.SessionUser.RoleId == 1)
                    {
                        TinRequestForm.ForEach(DisableItem);
                    }

                    SubmitButton.Visible  = Global.SessionUser.RoleId == 1 ? false : true;
                    ApproveButton.Visible = false;
                    RejectButton.Visible  = false;
                    break;
                }
            }
        }
        private void SubmitRecord()
        {
            try
            {
                Model.ITINRequest request = new Model.ITINRequest();

                request = (Boolean)ViewState["IsNewRecord"] == true ? request : (ITINRequest)Session["TinRequest"];

                request.LastName   = (string)TinRequestForm.GetNestedControlValueByFieldName("LastName");
                request.FirstName  = (string)TinRequestForm.GetNestedControlValueByFieldName("FirstName");
                request.MiddleName = (string)TinRequestForm.GetNestedControlValueByFieldName("MiddleName");

                request.BVN    = (string)TinRequestForm.GetNestedControlValueByFieldName("BVN");
                request.JTBTIN = (string)TinRequestForm.GetNestedControlValueByFieldName("JTBTIN");
                request.NIN    = (string)TinRequestForm.GetNestedControlValueByFieldName("NIN");

                request.Title          = (string)TinRequestForm.GetNestedControlValueByFieldName("Title");
                request.MaritalStatus  = (string)TinRequestForm.GetNestedControlValueByFieldName("MaritalStatus");
                request.Gender         = (string)TinRequestForm.GetNestedControlValueByFieldName("Gender");
                request.BirthDate      = (DateTime)TinRequestForm.GetNestedControlValueByFieldName("BirthDate");
                request.BirthCity      = (string)TinRequestForm.GetNestedControlValueByFieldName("BirthCity");
                request.BirthCountryId = int.Parse(TinRequestForm.GetNestedControlValueByFieldName("BirthCountryId").ToString());
                request.BirthStateId   = (string)TinRequestForm.GetNestedControlValueByFieldName("BirthStateId");

                request.NationalityId = int.Parse(TinRequestForm.GetNestedControlValueByFieldName("NationalityId").ToString());

                request.OriginStateId = (string)TinRequestForm.GetNestedControlValueByFieldName("OriginStateId");

                if (!string.IsNullOrEmpty(OriginLgaCombo.Text))
                {
                    request.OriginLgaId = int.Parse(TinRequestForm.GetNestedControlValueByFieldName("OriginLgaId").ToString());
                }

                request.Employer         = (string)TinRequestForm.GetNestedControlValueByFieldName("Employer");
                request.EmploymentId     = (string)TinRequestForm.GetNestedControlValueByFieldName("EmploymentId");
                request.Employer         = (string)TinRequestForm.GetNestedControlValueByFieldName("Employer");
                request.EmploymentStatus = (string)TinRequestForm.GetNestedControlValueByFieldName("EmploymentStatus");
                request.Profession       = (string)TinRequestForm.GetNestedControlValueByFieldName("Profession");

                request.IdentificationNumber = (string)TinRequestForm.GetNestedControlValueByFieldName("IdentificationNumber");
                request.IdentificationType   = (string)TinRequestForm.GetNestedControlValueByFieldName("IdentificationType");

                request.Phone1      = (string)TinRequestForm.GetNestedControlValueByFieldName("Phone1").ToString();
                request.Phone2      = (string)TinRequestForm.GetNestedControlValueByFieldName("Phone2");
                request.Email       = (string)TinRequestForm.GetNestedControlValueByFieldName("Email");
                request.Website     = (string)TinRequestForm.GetNestedControlValueByFieldName("Website");
                request.TaxOfficeId = (string)TinRequestForm.GetNestedControlValueByFieldName("TaxOfficeId");

                request.StreetNo       = (string)TinRequestForm.GetNestedControlValueByFieldName("StreetNo");
                request.AddressLine1   = (string)TinRequestForm.GetNestedControlValueByFieldName("AddressLine1");
                request.AddressLine2   = (string)TinRequestForm.GetNestedControlValueByFieldName("AddressLine2");
                request.AddressCity    = (string)TinRequestForm.GetNestedControlValueByFieldName("AddressCity");
                request.AddressStateId = (string)TinRequestForm.GetNestedControlValueByFieldName("AddressStateId");

                if (!string.IsNullOrEmpty(TinRequestForm.GetNestedControlValueByFieldName("AddressLgaId").ToString()))
                {
                    request.AddressLgaId = int.Parse(TinRequestForm.GetNestedControlValueByFieldName("AddressLgaId").ToString());
                }
                else
                {
                    request.AddressLgaId = null;
                }

                request.RecordSource = "FCTIRS";
                request.CreatedBy    = Global.SessionUser.UserName;
                request.CreateDate   = DateTime.Now;
                request.Status       = "Submitted";

                ValidateRecord(request);

                if ((Boolean)ViewState["IsNewRecord"] == true)
                {
                    context.ITINRequests.Add(request);
                    context.SaveChanges();
                }
                else
                {
                    context.SaveChanges();
                }

                DisplayAlert("Success", "Individual TIN Request", "TIN Request Submitted Successfully");

                TinRequestGridview.DataBind();
                TinRequestMultiView.ActiveViewIndex = 0;
            }
            catch (Exception ex)
            {
                DisplayAlert("Danger", "Individual TIN Request", ex.Message);
                return;
            }
        }