예제 #1
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));
        }
예제 #2
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 }));
        }