public ActionResult SaveEditEntriesDateWise(AttEditSingleEmployee Model)
        {
            try
            {
                int      _UserID      = Convert.ToInt32(Session["LoggedUserID"].ToString());
                int      count        = Convert.ToInt32(Request.Form["Count"].ToString());
                DateTime dt           = Convert.ToDateTime(Request.Form["Date"].ToString());
                string   Criteria     = Request.Form["Criteria"].ToString();
                int      CriteriaData = Convert.ToInt32(Request.Form["CriteriaData"].ToString());
                List <Att_DailyAttendance> oldAttendance = new List <Att_DailyAttendance>();
                oldAttendance = db.Att_DailyAttendance.Where(aa => aa.AttDate == dt).ToList();
                string Message = "";
                for (int i = 0; i < count; i++)
                {
                    int    EmpID            = Convert.ToInt32(Request.Form["Row" + i.ToString()].ToString());
                    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))
                    {
                        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
                    {
                    }
                }
                using (var ctx = new HRMEntities())
                {
                    List <Att_DailyAttendance> dailyAttendance = new List <Att_DailyAttendance>();
                    switch (Criteria)
                    {
                    case "rbAll":
                        dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.AttDate == dt).OrderByDescending(aa => aa.EmpID).ToList();
                        Criteria        = "rbAll";
                        break;

                    case "rbShift":
                        dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.HR_Employee.ShiftID == CriteriaData && aa.AttDate == dt).OrderByDescending(aa => aa.EmpID).ToList();
                        Criteria        = "rbShift";
                        break;

                    case "rbLocation":
                        dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.HR_Employee.LocationID == CriteriaData && aa.AttDate == dt).OrderByDescending(aa => aa.EmpID).ToList();
                        Criteria        = "rbLocation";
                        break;

                    //case "rbGroup":
                    //    dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.HR_Employee.GroupID == CriteriaData && aa.AttDate == dt).OrderByDescending(aa => aa.EmpID).ToList();
                    //    Criteria = "rbGroup";
                    //    break;
                    //case "rbDivision":
                    //    dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.HR_Employee.HR_Section.HR_Department.DivsionID == CriteriaData && aa.AttDate == dt).OrderByDescending(aa => aa.EmpID).ToList();
                    //    Criteria = "rbDivision";
                    //    break;
                    case "rbDepartment":
                        dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.HR_Employee.HR_Section.DepartmentID == CriteriaData && aa.AttDate == dt).OrderByDescending(aa => aa.EmpID).ToList();
                        Criteria        = "rbDepartment";
                        break;

                    case "rbSection":
                        dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.HR_Employee.SectionID == CriteriaData && aa.AttDate == dt).OrderByDescending(aa => aa.EmpID).ToList();
                        Criteria        = "rbSection";
                        break;
                    }
                    return(View("EditDateWiseEntries", EditAttManager.GetAttendanceAttributesDateWise(dailyAttendance, dt, Criteria, CriteriaData)));
                }
            }
            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;
            }
        }