public ActionResult Create(Attendance attendance)
        {
            if (ModelState.IsValid)
            {
                db.Attendances.AddObject(attendance);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.EmployeeId = new SelectList(db.Employees, "EmployeeId", "Name", attendance.EmployeeId);
            return View(attendance);
        }
 public ActionResult Edit(Attendance attendance)
 {
     if (ModelState.IsValid)
     {
         db.Attendances.Attach(attendance);
         db.ObjectStateManager.ChangeObjectState(attendance, EntityState.Modified);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.EmployeeId = new SelectList(db.Employees, "EmployeeId", "Name", attendance.EmployeeId);
     return View(attendance);
 }
 /// <summary>
 /// Create a new Attendance object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="date">Initial value of the Date property.</param>
 /// <param name="employeeId">Initial value of the EmployeeId property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 public static Attendance CreateAttendance(global::System.Int32 id, global::System.DateTime date, global::System.Int32 employeeId, global::System.String status)
 {
     Attendance attendance = new Attendance();
     attendance.Id = id;
     attendance.Date = date;
     attendance.EmployeeId = employeeId;
     attendance.Status = status;
     return attendance;
 }
        public ActionResult Update(FormCollection collection)
        {
            int id = Int32.Parse(Session["LogedUserId"].ToString());
            var leaveRequests = db.LeaveRequests.Include(c => c.Employee).Where(c => c.Employee.ManagerId == id);

            foreach (LeaveRequest leaveRequest in leaveRequests)
            {
                string status = (string)collection.Get("status" + leaveRequest.Id);
                Console.WriteLine("Status" + status);
                System.Diagnostics.Debug.WriteLine("Status :" + status);
                if (status != null)
                {
                    if (status.Equals("No"))
                    {
                        leaveRequest.Status = "Disapproved";
                    }
                    else if (status.Equals("Yes"))
                    {
                        leaveRequest.Status = "Approved";

                        for (DateTime d = leaveRequest.FromDate; d <= leaveRequest.ToDate; d=d.AddDays(1))
                        {
                            Attendance att = new Attendance();
                            att.EmployeeId = leaveRequest.Employee_Id;
                            if(leaveRequest.TypeOfLeave.Contains("Sick")){
                                Leave leave = db.Leaves.Where(l => l.EmployeeId == att.EmployeeId).FirstOrDefault();
                                if (leave.SickLeaves > 0)
                                {
                                    att.Status = "SickLeave";
                                }
                                leave.SickLeaves--;
                            }
                            else if(leaveRequest.TypeOfLeave.Contains("casual")){
                                Leave leave = db.Leaves.Where(l => l.EmployeeId == att.EmployeeId).FirstOrDefault();
                                if (leave.CasualLeaves > 0)
                                {
                                    att.Status = "CasualLeave";
                                }
                                leave.CasualLeaves--;
                            }
                            else if (leaveRequest.TypeOfLeave.Contains("Optional"))
                            {
                                Leave leave = db.Leaves.Where(l => l.EmployeeId == att.EmployeeId).FirstOrDefault();
                                if (leave.CasualLeaves > 0)
                                {
                                    att.Status = "OptionalLeave";
                                }
                                leave.OptionalHolidays--;
                            }
                            else
                            {
                                att.Status = "Absent";
                            }
                            att.Date = d;
                            db.Attendances.AddObject(att);
                        }

                    }
                }

                //AMSEntities newCtx = new AMSEntities();
                //newCtx.LeaveRequests.Attach(leaveRequest);
                //newCtx.ObjectStateManager.ChangeObjectState(leaveRequest, EntityState.Modified);

            }
            db.SaveChanges();
            return RedirectToAction("Index");
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Attendances EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAttendances(Attendance attendance)
 {
     base.AddObject("Attendances", attendance);
 }