示例#1
0
        public ActionResult Edit([Bind(Include = "HolidayID, Date, Description")] EditModel input)
        {
            var olddate = _holService.OldDate(input.HolidayID);
            var holiday = _holService.GetByID(input.HolidayID);

            input.ToHoliday(holiday);

            var model = new EditModel(holiday);

            if (model.Date.Date < DateTime.Now.Date)
            {
                ShowMessage("De feestdag kan niet plaatsvinden voor vandaag", MessageType.Danger);
                return(View("Create", model));
            }

            if (_holService.HolidayExists(holiday.Date, holiday.HolidayID))
            {
                ShowMessage("Op deze datum is al een feestdag gepland.", MessageType.Danger);
                return(View("Create", model));
            }

            if (ModelState.IsValid)
            {
                _holService.Save(holiday);
                TempData["Changed"] = "true";

                //Eerst kijken of er op de oude datum nog verlofverzoeken staan, hier eerst dagen aan toe voegen
                var oldlist = _vacreqService.CheckUsersHaveVacation(olddate);
                foreach (var item in oldlist)
                {
                    _mutvacService.SubtractMinutes(item.UserID, SecurityHelper.GetUserId(), item.TotalMinutes);
                }

                var list = _vacreqService.CheckUsersHaveVacation(holiday.Date);
                foreach (var item in list)
                {
                    _mutvacService.AddMinutes(item.UserID, SecurityHelper.GetUserId(), item.TotalMinutes);
                }

                return(RedirectToAction("Index", "Holiday"));
            }

            return(View(input));
        }