コード例 #1
0
        // POST: Year
        public ActionResult SelectYear(int year)
        {
            TimeSheetContainer model = new TimeSheetContainer();

            model.PeriodList = PayPeriod.GetPeriodItems(year);
            return(PartialView("_SelectYear", model));
        }
コード例 #2
0
        // GET: Year
        // POST: Year
        public ActionResult SelectYear(int?year)
        {
            TimeSheetContainer model = new TimeSheetContainer();

            model.PeriodList = PayPeriod.GetPeriodItems((year == null) ? DateTime.Now.Year : year.Value);
            return(PartialView("_SelectYear", model));
        }
コード例 #3
0
        // GET: TimeSheet
        public async Task <ActionResult> Index(int message = 0)
        {
            ViewBag.Manager = UserRoleSetting.GetManagerItems();
            int year   = DateTime.Now.Year;
            int period = (int)(DateTime.Now - PayPeriod.FirstPayDayOfYear(year)).Days / 14 + 2;
            TimeSheetContainer model = await GetTimeSheetModel(year, period);

            model.YearList = PayPeriod.GetYearItems();
            switch (message)
            {
            case 0:
                ViewBag.Message = "";
                break;

            case 1:
                ViewBag.Message = "Please save timesheet before submit";
                break;

            case 2:
                ViewBag.Message = "Timesheet approval email has been sent successfully";
                break;

            case 3:
                ViewBag.Message = "Timesheet has been saved successfully";
                break;

            default:
                ViewBag.Message = "no message";
                break;
            }
            return(View(model));
        }
コード例 #4
0
 //save or update time records to db
 public ActionResult SaveTimeSheet(TimeSheetContainer model)
 {
     if (Startup.NoRecords == true)
     {
         try
         {
             if (ModelState.IsValid)
             {
                 for (int i = 0; i < model.TimeRecords.Count; i++)
                 {
                     timesheetDb.TimeRecords.Add(model.TimeRecords[i]);
                 }
                 model.TimeRecordForm.status            = _status.modified;
                 model.TimeRecordForm.SubmittedTime     = DateTime.Now;
                 model.TimeRecordForm.TotalWorkingHours = CalculateTotalWorkingHours(model);
                 model.TimeRecordForm.TotalLeaveHours   = CalculateTotalLeaveHours(model);
                 timesheetDb.TimeRecordForms.Add(model.TimeRecordForm);
                 timesheetDb.SaveChanges();
             }
             return(RedirectToAction("Index", new { message = 3 }));
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
     else
     {
         try
         {
             if (ModelState.IsValid)
             {
                 for (int i = 0; i < model.TimeRecords.Count; i++)
                 {
                     timesheetDb.TimeRecords.Attach(model.TimeRecords[i]);
                     var entry = timesheetDb.Entry(model.TimeRecords[i]);
                     entry.Property(e => e.StartTime).IsModified  = true;
                     entry.Property(e => e.LunchBreak).IsModified = true;
                     entry.Property(e => e.EndTime).IsModified    = true;
                     entry.Property(e => e.Flexi).IsModified      = true;
                     timesheetDb.SaveChanges();
                 }
                 model.TimeRecordForm.status            = _status.modified;
                 model.TimeRecordForm.TotalWorkingHours = CalculateTotalWorkingHours(model);
                 model.TimeRecordForm.TotalLeaveHours   = CalculateTotalLeaveHours(model);
                 model.TimeRecordForm.SubmittedTime     = DateTime.Now;
                 timesheetDb.TimeRecordForms.Attach(model.TimeRecordForm);
                 timesheetDb.Entry(model.TimeRecordForm).State = EntityState.Modified;
                 timesheetDb.SaveChanges();
             }
             return(RedirectToAction("Index", new { message = 3 }));
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
コード例 #5
0
        /// <summary>
        ///     Create a tab page for user to apply casual work hours.
        /// </summary>
        /// <returns>A partial view with details of an application of casual work hours.</returns>
        public ActionResult Casual()
        {
            TimeSheetContainer model = new TimeSheetContainer();

            //get droplists of year and managers
            model.YearList  = PayPeriod.GetYearItems();
            ViewBag.Manager = UserRoleSetting.GetManagerItems();

            return(PartialView("_Casual", model));
        }
コード例 #6
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));
        }
コード例 #7
0
        //Calculate the total leaving hours to current date
        private double CalculateTotalLeaveHours(TimeSheetContainer model)
        {
            double   leaveHours = 0;
            DateTime current    = DateTime.Now.Date;

            for (int i = 0; i <= Convert.ToInt32((current - model.TimeRecords[0].RecordDate).TotalDays); i++)
            {
                leaveHours += model.TimeRecords[i].LeaveTime;
            }
            return(leaveHours);
        }
コード例 #8
0
        //Calculate the total working hours to current date
        private double CalculateTotalWorkingHours(TimeSheetContainer model)
        {
            double   workingHours = 0;
            DateTime current      = DateTime.Now.Date;

            for (int i = 0; i <= Convert.ToInt32((current - model.TimeRecords[0].RecordDate).TotalDays); i++)
            {
                workingHours += model.TimeRecords[i].WorkHours;
            }
            return(workingHours);
        }
コード例 #9
0
        // GET: LeaveApplication/_Casual
        public ActionResult Casual()
        {
            int year   = DateTime.Now.Year;
            int period = (int)(DateTime.Now - PayPeriod.FirstPayDayOfYear(year)).Days / 14 + 2;
            TimeSheetContainer model = CreateCasualList(year, period);

            model.YearList = PayPeriod.GetYearItems();
            //get manager droplist
            ViewBag.Manager = Manager.GetManagerItems();

            return(PartialView(@"~/Views/LeaveApplication/_Casual.cshtml", model));
        }
コード例 #10
0
        // GET: TimesheetApproval/ApprovalDetail
        public ActionResult ApprovalDetail(string id)
        {
            int formID = Convert.ToInt32(id);
            TimeSheetContainer model = new TimeSheetContainer();
            TimeRecordForm     form  = contextDb.TimeRecordForms.Find(formID);

            if (form != null)
            {
                // Format period with dates
                DateTime start = PayPeriod.GetStartDay(form.Year, form.Period);
                DateTime end   = PayPeriod.GetEndDay(form.Year, form.Period);
                ViewBag.Period = form.Period.ToString() + String.Format(" ({0:dd/MM} - {1:dd/MM})", start, end);

                // Get manager names
                List <string> managerNames = new List <string>();
                foreach (var managerId in form._managerIDs)
                {
                    managerNames.Add(contextDb.ADUsers.Find(managerId).UserName);
                }
                ViewBag.Managers = managerNames;

                // Get TimeRecords
                List <TimeRecord> timeRecords = (from t in contextDb.TimeRecords
                                                 where t.UserID == form.UserID &&
                                                 t.RecordDate >= start && t.RecordDate <= end
                                                 select t).ToList();

                model.TimeRecordForm = form;
                model.TimeRecords    = timeRecords.Where(t => t.WorkHours != 0).ToList();
                return(View(model));
            }
            else
            {
                return(HttpNotFound("Cannot find the timesheet in database. Please contact our IT support."));
            }
        }
コード例 #11
0
        public ActionResult Casual(TimeSheetContainer model)
        {
            if (Startup.NoRecords == true)
            {
                try
                {
                    if (ModelState.IsValid)
                    {
                        for (int i = 0; i < model.TimeRecords.Count; i++)
                        {
                            contextDb.TimeRecords.Add(model.TimeRecords[i]);
                        }
                        model.TimeRecordForm.FormStatus   = TimeRecordForm._formstatus.modified;
                        model.TimeRecordForm.SumbitStatus = TimeRecordForm._sumbitstatus.saved;
                        model.TimeRecordForm.SubmitTime   = DateTime.Now;

                        //Calculate the total working hours to current date
                        double   workingHours = 0;
                        DateTime current      = DateTime.Now.Date;
                        for (int i = 0; i <= Convert.ToInt32((current - model.TimeRecords[0].RecordDate).TotalDays); i++)
                        {
                            workingHours += model.TimeRecords[i].WorkHours;
                        }
                        model.TimeRecordForm.TotalWorkingHours = workingHours;

                        model.TimeRecordForm.TotalLeaveHours = 0;
                        contextDb.TimeRecordForms.Add(model.TimeRecordForm);
                        contextDb.SaveChanges();
                    }
                    return(RedirectToAction("Index", new { message = 3 }));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                try
                {
                    if (ModelState.IsValid)
                    {
                        for (int i = 0; i < model.TimeRecords.Count; i++)
                        {
                            contextDb.TimeRecords.Attach(model.TimeRecords[i]);
                            var entry = contextDb.Entry(model.TimeRecords[i]);
                            entry.Property(e => e.StartTime).IsModified  = true;
                            entry.Property(e => e.LunchBreak).IsModified = true;
                            entry.Property(e => e.EndTime).IsModified    = true;
                            entry.Property(e => e.Flexi).IsModified      = true;
                            contextDb.SaveChanges();
                        }
                        model.TimeRecordForm.FormStatus   = TimeRecordForm._formstatus.modified;
                        model.TimeRecordForm.SumbitStatus = TimeRecordForm._sumbitstatus.saved;

                        //Calculate the total working hours to current date
                        double   workingHours = 0;
                        DateTime current      = DateTime.Now.Date;
                        for (int i = 0; i <= Convert.ToInt32((current - model.TimeRecords[0].RecordDate).TotalDays); i++)
                        {
                            workingHours += model.TimeRecords[i].WorkHours;
                        }
                        model.TimeRecordForm.TotalWorkingHours = workingHours;

                        model.TimeRecordForm.TotalLeaveHours = 0;
                        model.TimeRecordForm.SubmitTime      = DateTime.Now;
                        contextDb.TimeRecordForms.Attach(model.TimeRecordForm);
                        contextDb.Entry(model.TimeRecordForm).State = EntityState.Modified;
                        contextDb.SaveChanges();
                    }
                    return(RedirectToAction("Index", new { message = 3 }));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
コード例 #12
0
        public ActionResult Casual(TimeSheetContainer model)
        {
            try
            {
                TempData["model"] = model;
                if (ModelState.IsValid)
                {
                    double workingHours = 0;
                    string userId       = User.Identity.Name;
                    for (int i = 0; i < model.TimeRecords.Count; i++)
                    {
                        // Add/Update each TimeRecords
                        DateTime recordDate = model.TimeRecords[i].RecordDate;
                        var      record     = contextDb.TimeRecords.Where(t => t.UserID == userId &&
                                                                          t.RecordDate == recordDate).FirstOrDefault();
                        if (record == null)
                        {
                            contextDb.TimeRecords.Add(model.TimeRecords[i]);
                        }
                        else
                        {
                            record.StartTime              = model.TimeRecords[i].StartTime;
                            record.EndTime                = model.TimeRecords[i].EndTime;
                            record.LunchBreak             = model.TimeRecords[i].LunchBreak;
                            contextDb.Entry(record).State = EntityState.Modified;
                        }
                        // Calculate total working hours
                        workingHours += model.TimeRecords[i].WorkHours;
                    }
                    model.TimeRecordForm.TotalWorkingHours = workingHours;
                    model.TimeRecordForm.SubmittedTime     = DateTime.Now;

                    // Add/Update TimeSheetForm data
                    var form = contextDb.TimeRecordForms.Where(t => t.UserID == userId &&
                                                               t.Year == model.TimeRecordForm.Year &&
                                                               t.Period == model.TimeRecordForm.Period).FirstOrDefault();
                    if (form == null)
                    {
                        model.TimeRecordForm.status   = _status.submited;
                        model.TimeRecordForm.UserID   = User.Identity.Name;
                        model.TimeRecordForm.UserName = contextDb.ADUsers.Find(User.Identity.Name).UserName;
                        contextDb.TimeRecordForms.Add(model.TimeRecordForm);
                    }
                    else
                    {
                        form.status                 = _status.modified;
                        form.TotalWorkingHours      = model.TimeRecordForm.TotalWorkingHours;
                        form.ManagerIDs             = model.TimeRecordForm.ManagerIDs;
                        form.Comments               = model.TimeRecordForm.Comments;
                        contextDb.Entry(form).State = EntityState.Modified;
                    }
                    contextDb.SaveChanges();

                    // send email to manager
                    form = (from f in contextDb.TimeRecordForms
                            where f.Period == model.TimeRecordForm.Period
                            where f.Year == model.TimeRecordForm.Year
                            where f.UserID == model.TimeRecordForm.UserID
                            select f).FirstOrDefault();

                    if (form != null)
                    {
                        foreach (var mangerId in form._managerIDs)
                        {
                            Task.Run(() => EmailSetting.SendEmail(mangerId, string.Empty, "TimesheetApplication", form.TimeRecordFormId.ToString()));
                        }
                    }
                    return(RedirectToAction("PostRequest", new { status = postRequestStatus.success }));
                }
                //TempData["ErrorModel"] = ModelState.Values;
                return(RedirectToAction("PostRequest", new { status = postRequestStatus.fail }));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }