Пример #1
0
        public List <LeaveCalendarEntity> GetApprovedLeaves()
        {
            List <LeaveCalendarEntity> rType = new List <LeaveCalendarEntity>();
            //Default get Last 2 months Data
            List <LeaveRequestEntity> RequestList = LeaveServices.GetLeave(0, 0, 0, (int)LeaveServices.Leave_status_Type.Approved, DateTime.UtcNow.AddMonths(-2), null, 0);

            rType = (from l in RequestList
                     select new LeaveCalendarEntity
            {
                id = l.RequestId,
                title = l.Name + " taken leave for " + l.LeaveDurationType,
                start = l.StartTime,
                end = (DateTime)l.StartTime.AddHours((int)l.TotalDays * 24),
                color = "#3A87AD"
            }).ToList();
            DateTime CurrentDate = DateTime.UtcNow;

            try
            {
                CurrentDate = CurrentDate.Subtract(HRMHelper.TimeDiffrence);
            }
            catch
            { }
            CurrentDate = DateTime.Parse(CurrentDate.ToShortDateString());
            List <UserEntity>          UserList         = UserServices.GetTodayNotPunchInUsers();
            List <LeaveCalendarEntity> UserCalenderList = (from u in UserList
                                                           select new LeaveCalendarEntity
            {
                id = u.UserId,
                title = u.Name + " not punchin",
                start = CurrentDate,
                end = CurrentDate,
                color = "#FF4500"
            }).ToList();

            rType.AddRange(UserCalenderList);
            return(rType);
        }
Пример #2
0
        public ActionResult LeaveRecords()
        {
            int ManagerId = 0;
            int UserId    = 0;
            List <LeaveRequestEntity> lstRequest = new List <LeaveRequestEntity>();

            if (User.IsInRole("Admin"))
            {
                ViewBag.UserList = UserServices.GetAllUser();
            }
            if (User.IsInRole("Manager"))
            {
                ViewBag.UserList = UserServices.GetUserByManagerId(HRMHelper.CurrentUser.UserId);
                ManagerId        = HRMHelper.CurrentUser.UserId;
            }

            if (Request.Form["lstUser"] != null)
            {
                int.TryParse(Request.Form["lstUser"].ToString(), out UserId);
            }
            ViewBag.SelectedUser = UserId;
            if ((!User.IsInRole("Manager")) && !User.IsInRole("Admin"))
            {
                UserId = HRMHelper.CurrentUser.UserId;
            }


            string _strStartDate = "";
            string _strEndDate   = "";

            if (Request.Form["txtStartDate"] != null)
            {
                _strStartDate = Request.Form["txtStartDate"].ToString();
            }
            if (Request.Form["txtEndDate"] != null)
            {
                _strEndDate = Request.Form["txtEndDate"].ToString();
            }

            ViewBag.StartDate = _strStartDate;
            ViewBag.EndDate   = _strEndDate;
            DateTime _startdate = new DateTime();
            DateTime _enddate   = new DateTime();
            DateTime?StartDate  = null;
            DateTime?EndDate    = null;

            if (_strStartDate != "")
            {
                DateTime.TryParseExact(_strStartDate, new string[] { "MM/dd/yyyy" }, CultureInfo.InvariantCulture, DateTimeStyles.None, out _startdate);
            }
            //else
            //{
            //    _startdate = new DateTime(DateTime.Now.Year, DateTime.Now.Month-1, 1);
            //}
            if (_strEndDate != "")
            {
                DateTime.TryParseExact(_strEndDate, new string[] { "MM/dd/yyyy" }, CultureInfo.InvariantCulture, DateTimeStyles.None, out _enddate);
            }
            if (_startdate != new DateTime())
            {
                _startdate = _startdate.Add(HRMHelper.TimeDiffrence);
                StartDate  = _startdate;
            }
            if (_enddate != new DateTime())
            {
                _enddate = _enddate.Subtract(HRMHelper.TimeDiffrence);
                EndDate  = _enddate;
            }
            List <LeaveStatusTypeEntity> LeaveStatusList     = LeaveServices.GetAllLeaveStatus();
            List <LeaveStatusTypeEntity> PersonalLeaveStatus = LeaveServices.GetAllLeaveStatus();
            List <LeaveRequestEntity>    model = new List <LeaveRequestEntity>();

            if (User.IsInRole("Admin") || User.IsInRole("Manager"))
            {
                LeaveStatusTypeEntity tempPendingApproval = LeaveStatusList.Where(l => l.StatusId == (int)LeaveServices.Leave_status_Type.PendingApproval).FirstOrDefault();
                LeaveStatusList.Remove(tempPendingApproval);
            }
            else
            {
                LeaveStatusTypeEntity tempApproval = LeaveStatusList.Where(l => l.StatusId == (int)LeaveServices.Leave_status_Type.Approved).FirstOrDefault();
                LeaveStatusTypeEntity tempDeclined = LeaveStatusList.Where(l => l.StatusId == (int)LeaveServices.Leave_status_Type.Declined).FirstOrDefault();
                LeaveStatusList.Remove(tempApproval);
                LeaveStatusList.Remove(tempDeclined);
            }

            {
                LeaveStatusTypeEntity tempApproval = PersonalLeaveStatus.Where(l => l.StatusId == (int)LeaveServices.Leave_status_Type.Approved).FirstOrDefault();
                LeaveStatusTypeEntity tempDeclined = PersonalLeaveStatus.Where(l => l.StatusId == (int)LeaveServices.Leave_status_Type.Declined).FirstOrDefault();
                PersonalLeaveStatus.Remove(tempApproval);
                PersonalLeaveStatus.Remove(tempDeclined);
            }
            if (User.IsInRole("Manager"))
            {
                if (UserId == 0)
                {
                    lstRequest = LeaveServices.GetLeaveByUserId(HRMHelper.CurrentUser.UserId, StartDate, EndDate);
                }
            }
            lstRequest.AddRange(LeaveServices.GetLeave(0, UserId, ManagerId, 0, StartDate, EndDate, 0));
            model = lstRequest.OrderBy(l => l.LeaveStatusId).ThenByDescending(l => l.RequestDate).ToList();
            ViewBag.TotalLeaves         = model.Where(s => s.LeaveStatusId == (int)LeaveServices.Leave_status_Type.Approved).Sum(s => s.TotalDays);
            ViewBag.LeaveStatus         = LeaveStatusList;
            ViewBag.PersonalLeaveStatus = PersonalLeaveStatus;
            return(View(model));
        }