Пример #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            CalendRecord calendRecord = db.CalendRecords.Find(id);

            db.CalendRecords.Remove(calendRecord);
            db.SaveChanges();
            return(RedirectToAction("Index/" + calendRecord.EmployeeID));
        }
Пример #2
0
 public ActionResult Edit([Bind(Include = "CalendRecordID,CalendRecordName,EmployeeID,DayTypeID")] CalendRecord calendRecord)
 {
     if (ModelState.IsValid)
     {
         db.Entry(calendRecord).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index/" + calendRecord.EmployeeID));
     }
     ViewBag.DayTypeID  = new SelectList(db.DayTypes, "DayTypeID", "DayTypeName", calendRecord.DayTypeID);
     ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "EmployeeName", calendRecord.EmployeeID);
     return(View(calendRecord));
 }
Пример #3
0
        // GET: CalendRecords/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CalendRecord calendRecord = db.CalendRecords.Find(id);

            if (calendRecord == null)
            {
                return(HttpNotFound());
            }
            return(View(calendRecord));
        }
Пример #4
0
        public ActionResult Create([Bind(Include = "CalendRecordID,CalendRecordName,EmployeeID,DayTypeID")] CalendRecord calRecSaving, int daysCount)
        {
            if (ModelState.IsValid)
            {
                // TO SAVE A FEW DAYS TOGETHER IN THE SAME TYPE :

                for (int i = 0; i < daysCount; i++)
                {
                    // DO NOT ADD NEW IF EXISTS !!!
                    // OVERWRITE IT !!!

                    DateTime currentRecordDate = calRecSaving.CalendRecordName.AddDays(i);

                    // REMOVING =ALL= DUPLICATES !!!!!!!!
                    // REMOVING =ALL= DUPLICATES !!!!!!!!

                    List <CalendRecord> records = (from r in db.CalendRecords
                                                   where r.CalendRecordName == currentRecordDate &&
                                                   r.EmployeeID == calRecSaving.EmployeeID
                                                   select r).ToList();
                    // TODO:
                    // REFACTORE THIS !!!!!!!!!
                    // REFACTORE THIS !!!!!!!!!
                    // REFACTORE THIS !!!!!!!!!
                    // REFACTORE THIS !!!!!!!!!

                    if (records.Capacity > 0)
                    {
                        foreach (var item in records)
                        {
                            db.CalendRecords.Remove(item);
                        }
                    }

                    db.CalendRecords.Add(new CalendRecord
                    {
                        EmployeeID       = calRecSaving.EmployeeID,
                        DayTypeID        = calRecSaving.DayTypeID,
                        CalendRecordID   = calRecSaving.CalendRecordID,
                        CalendRecordName = calRecSaving.CalendRecordName.AddDays(i)
                    });
                }
                db.SaveChanges();
                return(RedirectToAction("MonthView"));
            }
            ViewBag.DayTypeID  = new SelectList(db.DayTypes, "DayTypeID", "DayTypeName", calRecSaving.DayTypeID);
            ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "EmployeeName", calRecSaving.EmployeeID);
            return(View(calRecSaving));
        }
Пример #5
0
        // GET: CalendRecords/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CalendRecord calendRecord = db.CalendRecords.Find(id);

            if (calendRecord == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DayTypeID  = new SelectList(db.DayTypes, "DayTypeID", "DayTypeName", calendRecord.DayTypeID);
            ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "EmployeeName", calendRecord.EmployeeID);
            return(View(calendRecord));
        }
Пример #6
0
        // GET SHORT-DAY (BEFORE HOLYDAYS USUALLY) :
        public ActionResult AddShortDay(DateTime?shortDayDate)
        {
            if (shortDayDate == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            DateTime dayForChange = Convert.ToDateTime(shortDayDate);

            int currYr  = dayForChange.Year;
            int currMon = dayForChange.Month;

            int lastMonDay = DateTime.DaysInMonth(currYr, currMon);

            // TODO:
            // REFACTORE THIS !!!
            // REFACTORE THIS !!!
            // REFACTORE THIS !!!

            var actualEmplo = (from e in db.Employees
                               where e.WorkStart <= new DateTime(currYr, currMon, lastMonDay) &&
                               e.WorkEnd == null || e.WorkEnd >= new DateTime(currYr, currMon, 1)
                               select e).ToList();

            foreach (var item in actualEmplo)
            {
                CalendRecord rec = (from r in db.CalendRecords
                                    where r.CalendRecordName == dayForChange && r.EmployeeID == item.EmployeeID
                                    select r).FirstOrDefault();

                // IF THIS DAY NOS NOT RECORD YET :
                if (rec == null)
                {
                    // SET - 7 HOURS FOR THIS DAY (BECAUSE OF SHORT DAY) :
                    db.CalendRecords.Add(new CalendRecord
                    {
                        CalendRecordName = dayForChange,
                        EmployeeID       = item.EmployeeID,
                        DayTypeID        = 7
                    });
                }
            }
            db.SaveChanges();

            return(RedirectToAction("MonthView"));
        }