//Load Edit Entries View
 public ActionResult EditMultipleEntries()
 {
     try
     {
         if (Request.Form["EmpNo"].ToString() != "" && Request.Form["DateFrom"].ToString() != "" && Request.Form["DateTo"].ToString() != "")
         {
             string   _EmpNo       = Request.Form["EmpNo"].ToString();
             DateTime _AttDataFrom = Convert.ToDateTime(Request.Form["DateFrom"].ToString());
             DateTime _AttDataTo   = Convert.ToDateTime(Request.Form["DateTo"].ToString());
             List <Att_DailyAttendance> dailyAttendance = new List <Att_DailyAttendance>();
             dailyAttendance = db.Att_DailyAttendance.Where(aa => aa.EmpNo == _EmpNo && aa.AttDate >= _AttDataFrom && aa.AttDate <= _AttDataTo).ToList();
             if (dailyAttendance.Count > 0)
             {
                 return(View(EditAttManager.GetAttendanceAttributes(dailyAttendance, _AttDataFrom, _AttDataTo)));
             }
             else
             {
                 return(RedirectToAction("Index"));
             }
         }
         return(View());
     }
     catch (Exception)
     {
         throw;
     }
 }
        public ActionResult SaveEditEntries(AttEditSingleEmployee Model)
        {
            try
            {
                bool     edited  = false;
                int      _UserID = Convert.ToInt32(Session["LoggedUserID"].ToString());
                int      empID   = Convert.ToInt32(Request.Form["empID"].ToString());
                DateTime dtFrom  = Convert.ToDateTime(Request.Form["dateFrom"].ToString());
                DateTime dtTo    = Convert.ToDateTime(Request.Form["dateTo"].ToString());
                List <Att_DailyAttendance> oldAttendance = new List <Att_DailyAttendance>();
                oldAttendance = db.Att_DailyAttendance.Where(aa => aa.EmpID == empID && aa.AttDate >= dtFrom && aa.AttDate <= dtTo).ToList();
                for (int i = 0; i < oldAttendance.Count; i++)
                {
                    string empDate          = Request.Form["EmpDate" + i.ToString()].ToString();
                    Att_DailyAttendance att = oldAttendance.First(aa => aa.EmpDate == empDate);
                    string DutyCode         = Request.Form["DutyCode" + i.ToString()].ToString();
                    string DutyTime         = Request.Form["DutyTime" + i.ToString()].ToString();
                    string ShiftTime        = Request.Form["ShiftTime" + i.ToString()].ToString();
                    //string TimeIn = Request.Form["TimeIn" + i.ToString()].ToString();
                    //string TimeOut = Request.Form["TimeOut" + i.ToString()].ToString();
                    string             TIn1     = Request.Form["TimeIn1" + i.ToString()].ToString();
                    string             TOut1    = Request.Form["TimeOut1" + i.ToString()].ToString();
                    string             TIn2     = Request.Form["TimeIn2" + i.ToString()].ToString();
                    string             TOut2    = Request.Form["TimeOut2" + i.ToString()].ToString();
                    string             TIn3     = Request.Form["TimeIn3" + i.ToString()].ToString();
                    string             TOut3    = Request.Form["TimeOut3" + i.ToString()].ToString();
                    string             Remarks  = Request.Form["Remarks" + i.ToString()].ToString();
                    EditAttendanceList editlist = EditAttManager.GetEditAttendanceList(empDate, DutyCode, DutyTime, ShiftTime, TIn1, TOut1, TIn2, TOut2, TIn3, TOut3, Remarks);
                    if (EditAttManager.CheckRecordIsEdited(att, editlist))
                    {
                        edited = true;
                        DateTime _NewTimeIn  = new DateTime();
                        DateTime _NewTimeOut = new DateTime();
                        DateTime?_NewTimeIn1;
                        DateTime?_NewTimeOut1;
                        DateTime?_NewTimeIn2;
                        DateTime?_NewTimeOut2;
                        DateTime?_NewTimeIn3;
                        DateTime?_NewTimeOut3;
                        _NewTimeIn = (DateTime)(att.AttDate + editlist.TimeIn);

                        if (editlist.TimeIn != null && editlist.TimeOut != null)
                        {
                            if (editlist.TimeIn1 != null)
                            {
                                _NewTimeIn1 = (DateTime)(att.AttDate + editlist.TimeIn1);
                            }
                            else
                            {
                                _NewTimeIn1 = null;
                            }
                            if (editlist.TimeIn2 != null)
                            {
                                _NewTimeIn2 = (DateTime)(att.AttDate + editlist.TimeIn2);
                            }
                            else
                            {
                                _NewTimeIn2 = null;
                            }
                            if (editlist.TimeIn3 != null)
                            {
                                _NewTimeIn3 = (DateTime)(att.AttDate + editlist.TimeIn3);
                            }
                            else
                            {
                                _NewTimeIn3 = null;
                            }
                            if (editlist.TimeOut1 != null)
                            {
                                _NewTimeOut1 = (DateTime)(att.AttDate + editlist.TimeOut1);
                            }
                            else
                            {
                                _NewTimeOut1 = null;
                            }
                            if (editlist.TimeOut2 != null)
                            {
                                _NewTimeOut2 = (DateTime)(att.AttDate + editlist.TimeOut2);
                            }
                            else
                            {
                                _NewTimeOut2 = null;
                            }
                            if (editlist.TimeOut3 != null)
                            {
                                _NewTimeOut3 = (DateTime)(att.AttDate + editlist.TimeOut3);
                            }
                            else
                            {
                                _NewTimeOut3 = null;
                            }
                            if (editlist.TimeOut < editlist.TimeIn)
                            {
                                _NewTimeOut = att.AttDate.Value.AddDays(1) + editlist.TimeOut;
                            }
                            else
                            {
                                _NewTimeOut = (DateTime)(att.AttDate + editlist.TimeOut);
                            }
                            if (editlist.TimeOut1 < editlist.TimeIn1)
                            {
                                _NewTimeOut1 = att.AttDate.Value.AddDays(1) + editlist.TimeOut1;
                            }
                            if (editlist.TimeOut2 < editlist.TimeIn2)
                            {
                                _NewTimeOut2 = att.AttDate.Value.AddDays(1) + editlist.TimeOut2;
                            }
                            if (editlist.TimeOut3 < editlist.TimeIn3)
                            {
                                _NewTimeOut3 = att.AttDate.Value.AddDays(1) + editlist.TimeOut3;
                            }
                            ManualAttendanceProcess _pma = new ManualAttendanceProcess(editlist.EmpDate, "", false, _NewTimeIn, _NewTimeOut, editlist.DutyCode, _UserID, editlist.DutyTime, "", (short)editlist.ShiftTime.TotalMinutes, _NewTimeIn1, _NewTimeOut1, _NewTimeIn2, _NewTimeOut2, _NewTimeIn3, _NewTimeOut3, Remarks);
                        }
                        else
                        {
                            if (editlist.TimeIn.TotalMinutes > 0)
                            {
                                _NewTimeIn = (DateTime)(att.AttDate + editlist.TimeIn);
                            }
                            if (editlist.TimeOut.TotalMinutes > 0)
                            {
                                _NewTimeOut = (DateTime)(att.AttDate + editlist.TimeOut);
                            }
                            ManualAttendanceProcess _pma = new ManualAttendanceProcess(editlist.EmpDate, "", false, _NewTimeIn, _NewTimeOut, editlist.DutyCode, _UserID, editlist.DutyTime, "", (short)editlist.ShiftTime.TotalMinutes);
                        }
                    }
                    else
                    {
                    }
                }
                if (edited == true)
                {
                    DateTime dt = oldAttendance.OrderByDescending(aa => aa.AttDate).FirstOrDefault().AttDate.Value;
                    //Process Monthly if date is greater than 20 from start
                    ProcessSupportFunc.ProcessAttendanceRequestMonthly(new DateTime(dt.Year, dt.Month, 1), DateTime.Today, oldAttendance.FirstOrDefault().EmpID.ToString());
                }
                using (var ctx = new HRMEntities())
                {
                    List <Att_DailyAttendance> dailyAttendance = new List <Att_DailyAttendance>();
                    dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.EmpID == empID && aa.AttDate >= dtFrom && aa.AttDate <= dtTo).ToList();
                    return(View("EditMultipleEntries", EditAttManager.GetAttendanceAttributes(dailyAttendance, dtFrom, dtTo)));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }