// GET: LeaveApplication/CreateLeaveForm
        public ActionResult CreateLeaveList(DateTime start, DateTime end, _leaveType leaveType)
        {
            // Try to fetch Leaveapplication from DB if it exists
            LeaveApplicationViewModel applicationVM  = new LeaveApplicationViewModel();
            List <TimeRecord>         newTimeRecords = new List <TimeRecord>();

            ViewBag.LeaveType = LeaveApplication.GetLeaveTypeItems();

            for (int i = 0; i <= (end - start).Days; i++)
            {
                // Fetch each timerecord in DB if it exists
                DateTime currentDate   = start.AddDays(i);
                var      newTimeRecord = new TimeRecord(currentDate.Date);
                newTimeRecord.SetAttendence(null, null, 0);
                newTimeRecord.UserID    = User.Identity.Name;
                newTimeRecord.LeaveType = leaveType;
                newTimeRecord.LeaveTime = (leaveType == 0) ? 0 : 7.5;
                PayPeriod.SetPublicHoliday(newTimeRecord);
                if (!newTimeRecord.IsHoliday)
                {
                    newTimeRecords.Add(newTimeRecord);
                }
            }
            applicationVM.TimeRecords = newTimeRecords;

            if (applicationVM.TimeRecords.Count == 0)
            {
                return(Content("No working days were found."));
            }

            return(PartialView(@"~/Views/LeaveApplication/_LeaveList.cshtml", applicationVM));
        }
Esempio n. 2
0
        /// <summary>
        ///     Create a list of <see cref="TimeRecord"/> for the applicant to edit details
        ///     on each day.
        /// </summary>
        /// <param name="year">The year of a pay period.</param>
        /// <param name="period">The pay period in a year.</param>
        /// <returns>A partial view with a list of <see cref="TimeRecord"/> to edit work hours.</returns>
        public ActionResult CreateCasualList(int year, int period)
        {
            TimeSheetContainer model = new TimeSheetContainer();

            model.TimeRecordForm = new TimeRecordForm();
            model.TimeRecords    = new List <TimeRecord>();

            DateTime firstPayDay = PayPeriod.GetStartDay(year, period);

            var form = (from f in contextDb.TimeRecordForms
                        where f.Year == year
                        where f.Period == period
                        where f.UserID == User.Identity.Name
                        select f).FirstOrDefault();

            if (form == null)
            {
                Startup.NoRecords           = true;
                model.TimeRecordForm.Year   = year;
                model.TimeRecordForm.Period = period;
                model.TimeRecordForm.UserID = User.Identity.Name;
            }
            else
            {
                Startup.NoRecords    = false;
                model.TimeRecordForm = form;
            }

            for (int i = 0; i < 14; i++)
            {
                DateTime date   = firstPayDay.AddDays(i);
                var      record = (from r in contextDb.TimeRecords
                                   where r.RecordDate == date
                                   where r.UserID == User.Identity.Name
                                   select r).FirstOrDefault();
                if (record == null)
                {
                    TimeRecord r = new TimeRecord(date);
                    r.UserID = User.Identity.Name;
                    PayPeriod.SetPublicHoliday(r);
                    if (r.IsHoliday)
                    {
                        r.SetAttendence(null, null, 0);
                    }
                    model.TimeRecords.Add(r);
                }
                else
                {
                    PayPeriod.SetPublicHoliday(record);
                    model.TimeRecords.Add(record);
                }
            }

            return(PartialView("_CasualList", model));
        }
Esempio n. 3
0
        /// <summary>
        ///     Create a list of <see cref="TimeRecord"/> for the applicant to edit details
        ///     on each day of an HR application.
        /// </summary>
        /// <param name="start">The start day of the HR application</param>
        /// <param name="end">The end day of the HR application</param>
        /// <param name="leaveType">The main leave type of the application. It is also the default
        ///     leave type of each <see cref="TimeRecord"/> in the period.</param>
        /// <returns>A partial view with a list of <see cref="TimeRecord"/> to edit leave details.</returns>
        public ActionResult CreateLeaveList(DateTime start, DateTime end, _leaveType leaveType)
        {
            // Create new Leaveapplication
            LeaveApplicationViewModel model          = new LeaveApplicationViewModel();
            List <TimeRecord>         newTimeRecords = new List <TimeRecord>();
            //get leave type for holidays
            IEnumerable <SelectListItem> items = new List <SelectListItem>()
            {
                new SelectListItem
                {
                    Text     = "Flexi Hours (earned)",
                    Value    = _leaveType.flexiHours.ToString(),
                    Selected = true
                },
                new SelectListItem
                {
                    Text  = "Additional Hours",
                    Value = _leaveType.additionalHours.ToString()
                }
            };

            ViewBag.HolidayLeaveTypeItems = items;

            for (int i = 0; i <= (end - start).Days; i++)
            {
                // Create new timerecords
                DateTime currentDate   = start.AddDays(i);
                var      newTimeRecord = new TimeRecord(currentDate.Date);
                PayPeriod.SetPublicHoliday(newTimeRecord);

                newTimeRecord.LeaveTime = (newTimeRecord.IsHoliday) ? 0 : 7.60;
                newTimeRecord.SetAttendence(null, null, 0);
                newTimeRecord.UserID    = User.Identity.Name;
                newTimeRecord.LeaveType = leaveType;
                newTimeRecords.Add(newTimeRecord);
            }
            model.TimeRecords = newTimeRecords;

            return(PartialView("_LeaveList", model));
        }