Beispiel #1
0
        public bool WorkOverTime(OverTimeWork model)
        {
            using (ApplicationDbContext ctx = new ApplicationDbContext())
            {
                OverTime entity = ctx.OverTimeDays.SingleOrDefault(e => e.OTId == model.OTId);
                entity.IsAvailable = true;
                entity.OTDay       = model.OTDay;
                entity.HoursWorked = model.HoursWorked;
                entity.EmployeeId  = model.EmployeeId;

                return(ctx.SaveChanges() == 1);
            }
        }
        // // // // // // // //

        //GET: OverTime/Work/{id}
        public ActionResult Work(int id)
        {
            //OverTimeServices service = new OverTimeServices();
            OverTimeDetail detail = service.GetOTById(id);
            OverTimeWork   model  = new OverTimeWork
            {
                OTId        = detail.OTId,
                IsAvailable = detail.IsAvailable,
                OTDay       = detail.OTDay,
                HoursWorked = detail.HoursWorked
            };

            return(View(model));
        }
        public ActionResult Work(int id, OverTimeWork model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.OTId != id)
            {
                ModelState.AddModelError("", "ID does not match.");
                return(View(model));
            }

            //OverTimeServices service = new OverTimeServices();

            if (service.WorkOverTime(model))
            {
                TempData["SaveOTWork"] = $"OverTime {model.OTDay.ToLongDateString()} was updated.";
                return(RedirectToAction("ChooseOTList"));
            }

            ModelState.AddModelError("", "OverTime could not be updated.");
            return(View());
        }