Ejemplo n.º 1
0
        public Leave(LeaveStatus status, LeaveType type, Collaborator collaborator, DateTime startDate, DateTime endDate, string Start, string End)
        {
            Description             = collaborator.FirstName + " " + collaborator.LastName + " (" + collaborator.Service.Name + ")"; //generer un nom du type "NomPrenom (Service) - nbDemiJournées"
            Status                  = status;
            Type                    = type;
            Collaborator            = collaborator;
            StartDate               = startDate;
            EndDate                 = endDate;
            StartMorningOrAfternoon = Start;
            EndMorningOrAfternoon   = End;

            Treatment = HelperModel.ComputeTreatmentLeave(Collaborator);

            if (status == LeaveStatus.APPROVED)
            {
                this.Color = "#256cbf";
            }
            else if (status == LeaveStatus.PENDING_APPROVAL_1)
            {
                this.Color = "#c69b00";
            }
            else if (status == LeaveStatus.PENDING_APPROVAL_2)
            {
                this.Color = "#c68b90";
            }
            else
            {
                this.Color = "#bf4425";
            }
        }
Ejemplo n.º 2
0
        private bool CanChangeLeaveStatus(LeaveEntry leave, LeaveStatus leaveStatus, Employee actionEmployee)
        {
            switch (leaveStatus)
            {
            case LeaveStatus.Pending:
            case LeaveStatus.AwaitingDocumentation:     //Change
                return(true);

            case LeaveStatus.Approved:
                if (this.IsSickLeaveWithoutDocumentation(leave)) //Change
                {
                    return(false);                               //Change
                }
                return(leave.CurrentApprover.EmployeeId == actionEmployee.EmployeeId);

            case LeaveStatus.Finalized:
                if (this.IsSickLeaveWithoutDocumentation(leave)) //Change
                {
                    return(false);                               //Change
                }
                return(actionEmployee.IsManager());

            default:
                throw new ArgumentOutOfRangeException("leaveStatus");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Method to add Leave Status - SS
        /// </summary>
        /// <param name="name">name of LeaveStatus</param>
        /// <param name="instituteId">institute id</param>
        /// <returns>message</returns>
        public async Task <SharedLookUpResponse> AddLeaveStatusAsync(AddLeaveStatusManagementAc addLeaveStatus, int instituteId)
        {
            if (!await _iMSDbContext.LeaveStatuses.AnyAsync(x => x.InstituteId == instituteId && x.Code.ToLowerInvariant() == addLeaveStatus.Code.ToLowerInvariant()))
            {
                var LeaveStatus = new LeaveStatus()
                {
                    CreatedOn   = DateTime.UtcNow,
                    InstituteId = instituteId,
                    Name        = addLeaveStatus.Name,
                    Code        = addLeaveStatus.Code,
                    Description = addLeaveStatus.Description,
                    Status      = true,
                    IsEditable  = true
                };
                _iMSDbContext.LeaveStatuses.Add(LeaveStatus);
                await _iMSDbContext.SaveChangesAsync();

                return(new SharedLookUpResponse()
                {
                    HasError = false, Message = "Leave status added successfully"
                });
            }
            else
            {
                return new SharedLookUpResponse()
                       {
                           HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Leave status with the same code is already exist"
                       }
            };
        }
Ejemplo n.º 4
0
        public static void NonRecordedAttendance(int EmpId, DateTime day)
        {
            // 1. Check ExceptionAttendance for employee id.
            // 2. If employee exists, mark employee as present
            // 3. Else check for applications, mark employee as absent based on that.

            MEAPSDbEntities     context = new MEAPSDbEntities();
            ExceptionAttendance ea      = context.ExceptionAttendances.SingleOrDefault(x => (x.EmpId == EmpId) && (x.Date == day));

            if (ea != null) // if in exception attendance, mark as full present.
            {
                LeaveStatus ls = new LeaveStatus();
                ls.Date          = day;
                ls.EmployeeEmpId = EmpId;
                ls.PresenceState = "FP";
                context.LeaveStatuses.Add(ls);
                context.SaveChanges();
            }
            else                           // else check for applications
            {
                LeaveStatus ls = new LeaveStatus();
                ls.Date          = day;
                ls.EmployeeEmpId = EmpId;
                ls.PresenceState = "A";

                LeaveApplication la = context.LeaveApplications.SingleOrDefault(x => (x.Date == day) && (x.EmployeeEmpId == EmpId));
                if (la != null)
                {
                    string type = la.Type;
                    switch (type)
                    {
                    case "CL":
                        ls.FCL = 1;
                        break;

                    case "ML":
                        ls.FML = 1;
                        break;

                    case "EL":
                        ls.EL = 1;
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    ls.FCL = 1;
                }
                ls = LeaveDeduction.Deduct(ls);
                context.LeaveStatuses.Add(ls);
                context.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        public async Task <bool> UpdateStatus(LeaveStatus leaveStatus, int leaveId)
        {
            var result = await _dbContext.LeaveApplications.FirstOrDefaultAsync(x => x.Id == leaveId);

            if (result != null)
            {
                result.LeaveStatus = leaveStatus;
            }
            return(await _dbContext.SaveChangesAsync() >= 0);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Approve leave
        /// </summary>
        /// <param name="managerID">GUID of supervisor</param>
        /// <param name="leaveID">GUID of leave</param>
        /// <param name="status">Leave status</param>
        /// <returns>Approved leave</returns>
        public LeaveInfo ApproveLeave(string managerID, string leaveID, LeaveStatus status)
        {
            Log.Info(GlobalParams.StartApproveLeave);
            LeaveInfo result = null;

            try
            {
                result = LeaveBLL.ApproveLeave(managerID, leaveID, status);
                Employee employee = EmployeeBLL.GetEmployeeByID(result.FKSubmitEmployeeID.ToString());
                Employee manager  = EmployeeBLL.GetEmployeeByID(result.FKReportManagerID.ToString());
                if (result != null)
                {
                    Log.Info(GlobalParams.StartMail);
                    EmailConfig.SetRootPath(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath);
                    EmailContent ec = EmailConfig.EmailTemplates[EmailType.ApproveLeave.ToString()];
                    // {0} - First Name
                    // {1} - Manager First Name
                    // {2} - Hours
                    // {3} - Leave Type
                    // {4} - Reason
                    // {5} - Description
                    // {6} - Start
                    // {7} - End
                    // {8} - "Approved"
                    // {9} - ""
                    // {10} - CARSAddress
                    string emailBody = string.Format(ec.Body, employee.FirstName, manager.FirstName, result.Hours, result.Type.Name + " Leave", result.Reason, result.Description, result.FirstStartTime.ToString(EmailConfig.TimeFormatInEmail), result.LastEndTime.ToString(EmailConfig.TimeFormatInEmail), "Approved", "", EmailConfig.CARSAddress);
                    // {0} - First Name
                    // {1} - Hours
                    // {2} - Leave Type
                    // {3} - Manager First Name
                    // {4} - "Approved"
                    string emailTitle    = string.Format(ec.Title, employee.FirstName, result.Hours, result.Type.Name + " Leave", manager.FirstName, "Approved");
                    string employeeEmail = GetEmail(employee.Email);
                    string managerEmail  = GetEmail(employee.Manager.Email);
#if DEBUG
                    managerEmail = "*****@*****.**";
#endif
                    List <string> ccList = new List <string>();
                    ccList.Add(managerEmail);
                    SendMail sender = new SendMail(employeeEmail, ccList, EmailConfig.EmailAccount, emailBody, emailTitle, EmailConfig.Password, EmailConfig.Host);
                    sender.Send();
                    Log.Info(GlobalParams.EndMail);
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex.StackTrace);
                Log.Exception(ex.Message);
                throw ex;
            }
            Log.Info(GlobalParams.EndApproveLeave);

            return(result);
        }
Ejemplo n.º 7
0
 public void Status()
 {
     if (this.Available >= this.required)
     {
         LeaveStatus?.Invoke();
     }
     else
     {
         Console.WriteLine("Only {0} leaves are available!!!", this.Available);
     }
 }
Ejemplo n.º 8
0
 public Leave(string Creator, string manager, string title, string description, DateTime startDate, DateTime endDate)
 {
     this.LeaveId     = ++LastLeaveId;
     this.Creator     = Creator;
     this.Manager     = manager;
     this.Title       = title;
     this.Description = description;
     this.StartDate   = startDate;
     this.EndDate     = endDate;
     this.LeaveStatus = LeaveStatus.PENDING;
 }
Ejemplo n.º 9
0
        public virtual ActionResult ApproveRejectLeave(int id, LeaveStatus status)
        {
            var employeeLeave = _employeeLeaveRepository.GetById(id);

            _employeeLeaveRepository.Update(employeeLeave);
            employeeLeave.LeaveStatus = status;
            _unitOfWork.Commit();

            _logger.Info(LoggerMessages.INFO_LEAVE_APPROVE_REJECT, employeeLeave.EmployeeLeaveId, status.ToString(), User.Identity.GetUserId());
            return(RedirectToAction("EmployeeLeaves", new { month = DateTime.Now.Month, year = DateTime.Now.Year }));
        }
Ejemplo n.º 10
0
        private static Leave GetLeave(string line)
        {
            string[] leaveData = line.Split('|', StringSplitOptions.RemoveEmptyEntries);
            string[] dateSplit = leaveData[5].Split('-', StringSplitOptions.RemoveEmptyEntries);
            DateTime startDate = new DateTime(int.Parse(dateSplit[2]), int.Parse(dateSplit[1]), int.Parse(dateSplit[0]));

            dateSplit = leaveData[6].Split('-');
            DateTime    endDate     = new DateTime(int.Parse(dateSplit[2]), int.Parse(dateSplit[1]), int.Parse(dateSplit[0]));
            LeaveStatus leaveStatus = (LeaveStatus)Enum.Parse(typeof(LeaveStatus), leaveData[7], true);

            return(new Leave(int.Parse(leaveData[0]), leaveData[1], leaveData[2], leaveData[3], leaveData[4], startDate, endDate, leaveStatus));
        }
Ejemplo n.º 11
0
 public Leave(int leaveId, string Creator, string manager, string title, string description,
              DateTime startDate, DateTime endDate, LeaveStatus leaveStatus)
 {
     this.LeaveId     = leaveId;
     this.Creator     = Creator;
     this.Manager     = manager;
     this.Title       = title;
     this.Description = description;
     this.StartDate   = startDate;
     this.EndDate     = endDate;
     this.LeaveStatus = leaveStatus;
 }
Ejemplo n.º 12
0
 public Leave(Int32 id, string creator, string manager, string title, string description,
              DateTime startDate, DateTime endDate, LeaveStatus leaveStatus)
 {
     this.id          = id;
     this.creator     = creator;
     this.manager     = manager;
     this.title       = title;
     this.description = description;
     this.startDate   = startDate;
     this.endDate     = endDate;
     this.leaveStatus = leaveStatus;
 }
Ejemplo n.º 13
0
        public ActionResult <LeaveStatus> AddLeaveStatus(LeaveStatus leaveStatus)
        {
            int temp = _LeaveStatusService.AddLeaveStatus(leaveStatus);

            if (temp > 0)
            {
                return(CreatedAtAction(nameof(LeaveStatus), new { id = temp }, leaveStatus));
            }
            else
            {
                return(UnprocessableEntity("Leave Status already exist"));
            }
        }
Ejemplo n.º 14
0
        public ActionResult <LeaveStatus> UpdateLeaveStatus(LeaveStatus leaveStatus)
        {
            var d = _LeaveStatusService.UpdateLeaveStatus(leaveStatus);

            if (d != null)
            {
                return(d);
            }
            else
            {
                return(UnprocessableEntity("Leave Status does not exist"));
            }
        }
Ejemplo n.º 15
0
        public List <Leave> GetMyLeavesByStatus(LeaveStatus status)
        {
            List <Leave> leaves = GetMyLeaves();
            List <Leave> list   = new List <Leave> ();

            foreach (Leave leave in leaves)
            {
                if (leave.LeaveStatus == status)
                {
                    list.Add(leave);
                }
            }
            return(list);
        }
Ejemplo n.º 16
0
        public static void RecordedAttendance(int EmpId, DateTime day, TimeSpan EntryTime, TimeSpan ExitTime)
        {
            MEAPSDbEntities context          = new MEAPSDbEntities();
            TimeSpan        DefaultEntryTime = Convert.ToDateTime("9:50 AM").TimeOfDay;
            TimeSpan        DefaultExitTime  = Convert.ToDateTime("5:25 PM").TimeOfDay;
            LeaveStatus     ls = new LeaveStatus();

            ls.Date          = day;
            ls.EmployeeEmpId = EmpId;
            ls = Calculate(ls, EntryTime, ExitTime, day);
            ls = LeaveDeduction.Deduct(ls);
            context.LeaveStatuses.Add(ls);
            context.SaveChanges();
        }
Ejemplo n.º 17
0
        public List <Leave> GetAllLeavesApplicationsByStatus(LeaveStatus status)
        {
            List <Leave> leaves = this.GetAllLeavesApplications();
            List <Leave> list   = new List <Leave> ();

            foreach (Leave leave in leaves)
            {
                if (leave.LeaveStatus == status)
                {
                    list.Add(leave);
                }
            }
            return(list);
        }
Ejemplo n.º 18
0
        public int AddLeaveStatus(LeaveStatus d)
        {
            if (!LeaveStatusExists(d.Status))
            {
                _context.LeaveStatus.Add(d);
                _context.SaveChanges();

                return(d.LeaveStatusId);
            }
            else
            {
                return(0);
            }
        }
Ejemplo n.º 19
0
        public void UpdateStatus(int leaveId, LeaveStatus leaveStatus, Employee actionEmployee)
        {
            var leave = this.leaveRepository.FindById(leaveId);

            if (this.CanChangeLeaveStatus(leave, leaveStatus, actionEmployee))
            {
                leave.LeaveStatus = leaveStatus;
            }
            else
            {
                throw new Exception("Not Allowed #YOLO");
            }
            this.leaveRepository.Update(leave);
        }
Ejemplo n.º 20
0
        public static LeaveInfo ApproveLeave(string managerID, string leaveID, LeaveStatus status)
        {
            LeaveInfo leave = null;

            if (!string.IsNullOrEmpty(managerID) && !string.IsNullOrEmpty(leaveID) && status != LeaveStatus.None)
            {
                leave = LeaveBLL.GetLeaveInfoByID(leaveID);
                leave.FKReportManagerID = Guid.Parse(managerID);
                leave.PreStatus         = leave.Status;         // get previous status
                leave.Status            = status;
                leave.Save();
            }

            return(leave);
        }
Ejemplo n.º 21
0
        public static string GetLeaveStatusName(LeaveStatus leaveStatus)
        {
            switch (leaveStatus)
            {
            case LeaveStatus.Cannel:
                return("取消");

            case LeaveStatus.Pass:
                return("确认请假");

            case LeaveStatus.Submit:
                return("教师提交");
            }
            return("");
        }
Ejemplo n.º 22
0
 public override void FillEntity(DataRow row)
 {
     pkLeaveInfoID      = row["PKLeaveInfoID"] != DBNull.Value ? (Guid)row["PKLeaveInfoID"] : Guid.Empty;
     fkSubmitEmployeeID = row["FKSubmitEmployeeID"] != DBNull.Value ? (Guid)row["FKSubmitEmployeeID"] : Guid.Empty;
     fkReportManagerID  = row["FKReportManagerID"] != DBNull.Value ? (Guid)row["FKReportManagerID"] : Guid.Empty;
     fkLeaveTypeID      = row["FKLeaveTypeID"] != DBNull.Value ? (Guid)row["FKLeaveTypeID"] : Guid.Empty;
     status             = row["Status"] != DBNull.Value ? (LeaveStatus)Enum.Parse(typeof(LeaveStatus), row["Status"].ToString()) : (LeaveStatus)Enum.Parse(typeof(LeaveStatus), "None");
     reason             = row["Reason"] != DBNull.Value ? (String)row["Reason"] : null;
     firstStartTime     = row["FirstStartTime"] != DBNull.Value ? (DateTime)row["FirstStartTime"] : DateTime.MinValue;
     lastEndTime        = row["LastEndTime"] != DBNull.Value ? (DateTime)row["LastEndTime"] : DateTime.MinValue;
     description        = row["Description"] != DBNull.Value ? (String)row["Description"] : null;
     knowledgeDate      = row["KnowledgeDate"] != DBNull.Value ? (DateTime)row["KnowledgeDate"] : DateTime.MinValue;
     timeToken          = row["TimeToken"] != DBNull.Value ? (byte[])row["TimeToken"] : null;
     createdTime        = row["CreatedTime"] != DBNull.Value ? (DateTime)row["CreatedTime"] : DateTime.MinValue;
 }
Ejemplo n.º 23
0
        public ActionResult Review(long id, LeaveStatus status, string reason)
        {
            var taken = db.leaves_takens.Single(x => x.id == id);

            taken.status = (byte)status;
            taken.reason = reason;

            if (status == LeaveStatus.APPROVED)
            {
                // check that staff still has enough leave
                var alloc = taken.leaves_allocated;
                if (alloc.remaining.HasValue && taken.days > alloc.remaining)
                {
                    return(Json("Staff does not have enough leave remaining".ToJsonFail()));
                }

                if (alloc.remaining.HasValue)
                {
                    alloc.remaining -= taken.days;
                    Debug.Assert(alloc.remaining >= 0);
                }
            }

            repository.Save();

            // notify applicant
            var emailmodel = new LeaveNotification();

            emailmodel.receiver     = taken.user.ToName(false);
            emailmodel.leavetakenID = taken.id;
            emailmodel.status       = status.ToString();
            emailmodel.reason       = reason;

            this.SendEmailNow(
                EmailViewType.LEAVE_UPDATED,
                emailmodel,
                string.Format("Leave #{0} {1}", emailmodel.leavetakenID, emailmodel.status),
                taken.user.email,
                emailmodel.receiver);


            var viewmodel = "Leave application reviewed successfully".ToJsonOKMessage();

            viewmodel.data = this.RenderViewToString("IndexRows", new[] { taken }.ToModel(auth.perms.HasFlag(Permission.LEAVE_REVIEW), sessionid.Value, auth.perms));

            return(Json(viewmodel));
        }
Ejemplo n.º 24
0
        public static int GetNumberLeave(Collaborator coll, LeaveStatus status1, LeaveStatus status2, LeaveType type)
        {
            Dal dal    = new Dal();
            int number = 0;

            foreach (Leave l in dal.GetLeaves())
            {
                if ((l.Collaborator.Id == coll.Id) && CheckIfDateIsCurrentYear(l.StartDate))
                {
                    if ((l.Status == status1 | l.Status == status2) && l.Type == type)
                    {
                        number += l.ComputeLengthLeave();
                    }
                }
            }
            return(number);
        }
        static LeaveStatus Calculate(Int32 EmpId, TimeSpan EntryTime, TimeSpan ExitTime, DateTime Date, Int32 Type)
        {
            LeaveStatus ls = new LeaveStatus();

            ls.Date          = Date;
            ls.EmployeeEmpId = EmpId;

            TimeSpan nineFiftyAM      = Convert.ToDateTime("09:50 AM").TimeOfDay;
            TimeSpan tenAM            = Convert.ToDateTime("10:00 AM").TimeOfDay;
            TimeSpan tenThirtyAM      = Convert.ToDateTime("10:30 AM").TimeOfDay;
            TimeSpan oneThirtyPM      = Convert.ToDateTime("01:30 PM").TimeOfDay;
            TimeSpan threeThirtyPM    = Convert.ToDateTime("03:30 PM").TimeOfDay;
            TimeSpan fiveTwentyFivePM = Convert.ToDateTime("05:25 PM").TimeOfDay;



            return(ls);
        }
 public static void SearchLeavesByStatus(String leaveStatus)
 {
     try
     {
         LeaveStatus leaveSts = (LeaveStatus)Enum.Parse(typeof(LeaveStatus), leaveStatus, true);
         foreach (Leave leave in leaves)
         {
             if (leave.leaveStatus == leaveSts)
             {
                 Console.WriteLine(leave);
             }
         }
     }
     catch (Exception e)
     {
         throw new Exception("Invalid leave status in search, aborting", e);
     }
 }
Ejemplo n.º 27
0
 public ActionResult Index(EmployeeVM employeeVM)
 {
     try
     {
         using (IDbConnection cn = new SqlConnection(_connectionString))
         {
             cn.Open();
             employeeVM.Employee.DateTimeStampRecord(DbChangeType.Create);
             cn.Insert <Employee>(employeeVM.Employee);
             if (employeeVM.Employee.EmpId > 0)
             {
                 LeaveStatus leaveStatus = new LeaveStatus();
                 leaveStatus.EmpId = employeeVM.Employee.EmpId;
                 cn.Insert <LeaveStatus>(leaveStatus);
                 var user = new ApplicationUser()
                 {
                     UserName = employeeVM.Employee.Email, FirstName = employeeVM.Employee.EmpFirstName, LastName = employeeVM.Employee.EmpLastName, Email = employeeVM.Employee.Email
                 };
                 var result = UserManager.Create(user, employeeVM.Password.Trim());
                 if (result.Succeeded)
                 {
                     string defaultRole = UserRole.Employee.ToString();
                     if (employeeVM.Employee.IsSupervisor)
                     {
                         defaultRole = UserRole.Supervisor.ToString();
                     }
                     UserManager.AddToRole(user.Id, defaultRole);
                     var curUser = UserManager.FindByName(User.Identity.Name);
                     var task    = new Task(() => { MailUtility.SendAccountMail(employeeVM.Employee.EmpFirstName, employeeVM.Password.Trim(), employeeVM.Employee.Email, curUser.Email, curUser.FirstName); });
                     task.Start();
                     //MailUtility.SendAccountMail(employeeVM.Employee.EmpFirstName, employeeVM.Password, employeeVM.Employee.Email, curUser.Email, curUser.FirstName);
                 }
             }
             cn.Close();
         }
     }
     catch (Exception ex)
     {
         ConfigLogger.Instance.LogError(ex);
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 28
0
        private static void SearchLeave()
        {
            int choice;

            while ((choice = GetChoiceForSearchLeave()) != 0)
            {
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Enter Leave Title");
                    Leave leave = CurrentUser.GetMyLeavesByTitle(Console.ReadLine());
                    if (leave != null)
                    {
                        Console.WriteLine(leave.ToString());
                    }
                    else
                    {
                        Console.WriteLine("No leaves with current title");
                    }
                    break;

                case 2:
                    Console.WriteLine("Enter Leave Status");
                    try
                    {
                        LeaveStatus  status = (LeaveStatus)Enum.Parse(typeof(LeaveStatus), Console.ReadLine(), true);
                        List <Leave> leaves = CurrentUser.GetMyLeavesByStatus(status);
                        PrintLeaves(leaves);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("invalid value!!! Enter value from Approved,Rejected,Pending");
                    }
                    break;

                default:
                    Console.WriteLine("Enter valid Choice");
                    break;
                }
            }
        }
Ejemplo n.º 29
0
        private bool CanChangeLeaveStatus(LeaveEntry leave, LeaveStatus leaveStatus, Employee actionEmployee)
        {
            switch (leaveStatus)
            {
            case LeaveStatus.Pending:
                return(true);

            case LeaveStatus.Approved:
                return(leave.CurrentApprover.EmployeeId == actionEmployee.EmployeeId);

            case LeaveStatus.Finalized:
                if (leave.LeaveStatus != LeaveStatus.Approved)
                {
                    throw new ArgumentException("Cannot Finalize Leave");
                }
                return(actionEmployee.IsManager());

            default:
                throw new ArgumentOutOfRangeException("leaveStatus");
            }
        }
Ejemplo n.º 30
0
        protected void BtnRejectClick(object sender, EventArgs e)
        {
            try
            {
                int count  = 0;
                var leaves = new List <LeaveStatus>();

                foreach (var key in System.Web.HttpContext.Current.Request.Form.Keys)
                {
                    var leave = new LeaveStatus();

                    if (key.ToString().IndexOf("Chk") == 0)
                    {
                        if (System.Web.HttpContext.Current.Request.Form[key.ToString()].ToString().ToLower() == "on")
                        {
                            count++;
                            var Id       = key.ToString().Substring(key.ToString().IndexOf("Chk") + 3);
                            var comments = System.Web.HttpContext.Current.Request.Form["txt" + Id].ToString();
                            leave.Id     = int.Parse(Id);
                            leave.Reason = comments;
                            leaves.Add(leave);
                        }
                    }
                }

                if (leaves.Count != 0)
                {
                    ChangeStatus(leaves, "Rejected");
                    LoadDetails();
                }
                else
                {
                    lblErr.Text = "Please select the request(s) to reject";
                }
            }
            catch (Exception ex)
            {
                lblErr.Text = ex.Message;
            }
        }
 private bool CanChangeLeaveStatus(LeaveEntry leave, LeaveStatus leaveStatus, Employee actionEmployee)
 {
     switch(leaveStatus)
     {
         case LeaveStatus.Pending:
         case LeaveStatus.AwaitingDocumentation: //Change
             return true;
         case LeaveStatus.Approved:
             if (this.IsSickLeaveWithoutDocumentation(leave))//Change
             {
                 return false;//Change
             }
             return leave.CurrentApprover.EmployeeId == actionEmployee.EmployeeId;
         case LeaveStatus.Finalized:
             if (this.IsSickLeaveWithoutDocumentation(leave))//Change
             {
                 return false;//Change
             }
             return actionEmployee.IsManager();
         default:
             throw new ArgumentOutOfRangeException("leaveStatus");
     }
 }
 public void UpdateStatus(int leaveId, LeaveStatus leaveStatus, Employee actionEmployee)
 {
     var leave = this.leaveRepository.FindById(leaveId);
     if(this.CanChangeLeaveStatus(leave, leaveStatus, actionEmployee))
     {
         leave.LeaveStatus = leaveStatus;
     }
     else
     {
         throw new Exception("Not Allowed #YOLO");
     }
     this.leaveRepository.Update(leave);
 }
 private bool CanChangeLeaveStatus(LeaveEntry leave, LeaveStatus leaveStatus, Employee actionEmployee)
 {
     switch(leaveStatus)
     {
         case LeaveStatus.Pending:
             return true;
         case LeaveStatus.Approved:
             return leave.CurrentApprover.EmployeeId == actionEmployee.EmployeeId;
         case LeaveStatus.Finalized:
             if(leave.LeaveStatus != LeaveStatus.Approved)
             {
                 throw new ArgumentException("Cannot Finalize Leave");
             }
             return actionEmployee.IsManager();
         default:
             throw new ArgumentOutOfRangeException("leaveStatus");
     }
 }
        protected void BtnRejectClick(object sender, EventArgs e)
        {
            try
            {
                int count = 0;
                var leaves = new List<LeaveStatus>();

                foreach (var key in Request.Form.Keys)
                {
                    var leave = new LeaveStatus();

                    if (key.ToString().IndexOf("Chk") == 0)
                    {
                        if (Request.Form[key.ToString()].ToString().ToLower() == "on")
                        {
                            count++;
                            var Id = key.ToString().Substring(key.ToString().IndexOf("Chk") + 3);
                            var comments = Request.Form["txt" + Id].ToString();
                            leave.Id = int.Parse(Id);
                            leave.Reason = comments;
                            leaves.Add(leave);
                        }
                    }
                }

                //int count = 0;
                //var leaves = new List<LeaveStatus>();
                //foreach (GridViewRow row in grid.Rows)
                //{
                //    var checkbox = (CheckBox)row.FindControl("chkbox");
                //    if (checkbox.Checked)
                //    {
                //        var txtRemark = (TextBox)row.FindControl("txtreason");
                //        var leave = new LeaveStatus();
                //        count++;
                //        leave.Id = int.Parse(row.Cells[0].Text);
                //        leave.Reason = txtRemark.Text;
                //        leaves.Add(leave);
                //    }
                //}
                if (leaves.Count != 0)
                {
                    ChangeStatus(leaves, "Rejected");
                    LoadDetails();
                }
                else
                {
                    lblErr.Text = "Please select the request(s) to reject";
                }
            }
            catch (Exception ex)
            {
                lblErr.Text = ex.Message;
            }
        }