// GET: TimesheetApproval/TimeSheetOutput
        public ActionResult TimeSheetOutput(int id)
        {
            TimeRecordForm form = contextDb.TimeRecordForms.Find(id);

            // Get manager name
            ViewBag.ManagerName = contextDb.ADUsers.Find(form.ApprovedBy).UserName ?? string.Empty;
            // 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);
            return(View(form));
        }
 private ActionResult ApproveTimeSheet(TimeRecordForm form, string decision)
 {
     if (decision == "Approve")
     {
         form.status = _status.approved;
     }
     else if (decision == "Reject")
     {
         form.status = _status.rejected;
     }
     form.ApprovedBy             = User.Identity.Name;
     form.ApprovedTime           = DateTime.Now;
     contextDb.Entry(form).State = EntityState.Modified;
     contextDb.SaveChanges();
     Task.Run(() => EmailSetting.SendEmail(form.UserID, string.Empty, "TimesheetApproval", form.TimeRecordFormId.ToString()));
     return(RedirectToAction("Approval"));
 }
        public ActionResult ApprovalDetail(int id, string decision)
        {
            TimeRecordForm form = contextDb.TimeRecordForms.Find(id);

            if (form != null)
            {
                if (!User.IsInRole("Admin") && !form.ManagerIDs.Contains(User.Identity.Name))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest,
                                                    "You are not authoried to approve the timesheet"));
                }
                else
                {
                    ApproveTimeSheet(form, decision);
                }
            }
            else
            {
                return(HttpNotFound("Cannot find the timesheet in database. Please contact our IT support."));
            }

            return(RedirectToAction("Approval"));
        }
        // 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."));
            }
        }
        public ActionResult ApprovalPartial(int id, string decision, string type)
        {
            TimeRecordForm form = contextDb.TimeRecordForms.Find(id);

            if (form != null)
            {
                if (decision == "Approved")
                {
                    form.status = _status.approved;
                }
                else
                {
                    form.status = _status.rejected;
                }
                contextDb.Entry(form).State = EntityState.Modified;
                contextDb.SaveChanges();
            }
            else
            {
                return(HttpNotFound("Cannot find the timesheet in database. Please contact our IT support."));
            }

            return(View("_Approval", GetFormList(type)));
        }