public void LoadGridNormal()
 {
     UserClass objUser = new UserClass();
     int intCurrentUserId = objUser.GetCurrentUserByApp().Id;
     string CurrentUserLoginName = objUser.GetCurrentUserByApp().LoginName;
     TimeOffRequests objTOR = new TimeOffRequests();
     List<TimeOffRequests> objTORList = objTOR.GetMyProcessingRequests( intCurrentUserId, CurrentUserLoginName);
     //ProcessDateOnFulldays(ref objTOR);
     if (objTORList.Count > 0)
     {
         lvNormal.DataSource = objTORList;
         lvNormal.DataBind();
         lvNormal.Visible = true;
         this.dummyTable2.Visible = false;
     }
     else
     {
         this.lvNormal.Visible = false;
         this.dummyTable2.Visible = true;
     }                
 }
        public void VerifyApprover()
        {
            GroupsClass objTOR = new GroupsClass();
            if (Request.QueryString[Config.ListURL] != null)
                sharepointUrl = new Uri(Request.QueryString[Config.ListURL]);

            string siteApproverGroupname = Config.TimeOffApprovers;//default from web.config

            //Get from App Config (custom)
            ConfigListValues objConfigAppList = new ConfigListValues();
            objConfigAppList.GetConfigValues(null);
            if (objConfigAppList.items != null)
            {
                if (objConfigAppList.items[Config.TimeOffApprovers] != null)
                    siteApproverGroupname = objConfigAppList.items[Config.TimeOffApprovers].ToString();
            }

            UserClass objUser = new UserClass();
            string strCurrentUserTitle = objUser.GetCurrentUserByApp().LoginName;
            if (!objTOR.IsCurrentUserExistInGroup( siteApproverGroupname, strCurrentUserTitle))
            {
                lblerrmsg.Text = " You do not have Access Permission";
            }
            else
            {
                string deptCalName = Config.DepartmentCalendar;//default from web.config
                //Get from App Config (custom)
                ConfigListValues objConfAppList = new ConfigListValues();
                objConfAppList.GetConfigValues(null);
                if (objConfAppList.items != null)
                {
                    if (objConfAppList.items[deptCalName] != null)
                    {
                        deptCalName = objConfAppList.items[deptCalName].ToString();
                    }
                }
                Response.Redirect(Request.QueryString["SPHostUrl"] + "/_layouts/15/start.aspx#/Lists/" + deptCalName, false);
            }
        }
        public bool IsConcernedApprover(TimeOffRequests objTOR)
        {
            //GetCurrentuser and check is he among 3 approver
            // validate is he concern approver
            string concernedApprover="";
            UserClass objUser = new UserClass();         
            User CurrentUser= objUser.GetCurrentUserByApp();
            if (objTOR.Approver3 != null || objTOR.Approver3 != "")
                concernedApprover = objTOR.Approver3;
            else if (objTOR.Approver2 != null || objTOR.Approver2 != "")
                 concernedApprover = objTOR.Approver2;
                 else if (objTOR.Approver1 != null || objTOR.Approver1 != "")
                       concernedApprover = objTOR.Approver1;

            if (concernedApprover == "")
                return false;
            else
            {
                if (CurrentUser.Title == objTOR.Approver1)
                    return true;
                else
                    return false;
            }
        }
 public void LoadUser()
 {
     UserClass objUser = new UserClass();
     CurrentUser = objUser.GetCurrentUserByApp();
 }
        public void LoadGridCancel()
        {
           
                UserClass objUser = new UserClass();
                int intCurrentUserId = objUser.GetCurrentUserByApp().Id;

                TimeOffRequests objTOR = new TimeOffRequests();
                List<TimeOffRequests> objTORList = objTOR.GetMyCancelAlerts(intCurrentUserId);
                //ProcessDateOnFulldays(ref objTOR);
                if (objTORList.Count > 0)
                {
                    LVreqDetails.DataSource = objTORList;
                    LVreqDetails.DataBind();
                    LVreqDetails.Visible = true;
                    this.dummytable.Visible = false;
                }
                else
                {
                    LVreqDetails.Visible = false;
                    this.dummytable.Visible = false;
                    this.Table2.Visible = false;
                }            
           
        }
        public static bool ApproveRequest(string requestid)
        {
            if (HttpContext.Current.Session["CurrentSPContext"] != null)
            {
                TimeOffRequests obj = new TimeOffRequests();
                obj.RequestID = requestid;
                obj= obj.GetRequestDetailByRequestID(HttpContext.Current.Session["CurrentSPContext"] as SharePointContext);

                 UserClass objUser = new UserClass();
                 User CurrentUser = objUser.GetCurrentUserByApp(HttpContext.Current.Session["CurrentSPContext"] as SharePointContext);


                 int NumberofApprovers = 0, noOfApprovals = 0;
                 if (obj.Approver1 != "")
                     NumberofApprovers = 1;
                 if (obj.Approver2 != "")
                     NumberofApprovers = 2;
                 if (obj.Approver3 != "")
                     NumberofApprovers = 3;

                 if (obj.Approver1Status == "Approved")
                     noOfApprovals = 1;
                 if (obj.Approver2 != "Approved")
                     noOfApprovals = 2;
                 if (obj.Approver3 != "Approved")
                     noOfApprovals = 3;

                 bool sendCal = false;
                
                if(NumberofApprovers==1 && obj.Approver1Status == "Pending Approval" && obj.Approver1 == CurrentUser.LoginName)
                  {
                      obj.Approver1Status = "Approved";
                      obj.Status = "Approved";
                      sendCal = true;
                  }
               

                if (NumberofApprovers == 2 && obj.Approver1Status == "Approved" && obj.Approver2Status == "Pending Approval" && obj.Approver2 == CurrentUser.LoginName)
                {
                    obj.Approver2Status = "Approved";
                    obj.Status = "Approved";
                    sendCal = true;
                }

                if (NumberofApprovers == 3 && obj.Approver2Status == "Approved" && obj.Approver3Status == "Pending Approval" && obj.Approver3 == CurrentUser.LoginName)
                {
                    obj.Approver3Status = "Approved";
                    obj.Status = "Approved";
                    sendCal = true;
                }

                switch (noOfApprovals)
                {
                    case 0:
                        {
                            obj.Approver1Status = "Approved";
                            break;
                        }
                    case 1:
                        {
                            obj.Approver2Status = "Approved";
                            break;
                        }
                    case 3:
                        {
                            obj.Approver3Status = "Approved";
                            obj.Status = "Approved";
                            break;
                        }
                }
                bool updateResult=obj.UpdateRequest();



                if(sendCal)
                {
                    try
                    {
                        DeptCalListClass objDept = new DeptCalListClass();
                        objDept.AddDeptCal(null, obj.RequestedBy+ "-" + obj.TimeOffType, obj.StartDate.ToString(), obj.EndDate.ToString());
                    }
                    catch
                    { }
                }
              

            }
            return false;//TODO
        }