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

                return(ctx.SaveChanges() == 1);
            }
        }
        //GET: OverTime/Edit/{id}
        public ActionResult Edit(int id)
        {
            //OverTimeServices service = new OverTimeServices();
            OverTimeDetail detail = service.GetOTById(id);
            OverTimeEdit   model  = new OverTimeEdit
            {
                OTId = detail.OTId,
                //IsAvailable = detail.IsAvailable,
                OTDay = detail.OTDay,
                //HoursWorked = detail.HoursWorked
                Days = detail.Days
            };

            return(View(model));
        }
        public ActionResult Edit(int id, OverTimeEdit 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.UpdateOverTime(model))
            {
                TempData["SaveOTResult"] = $"OverTime {model.OTDay.ToLongDateString()} was updated.";
                return(RedirectToAction("Index"));
            }

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