public ActionResult Edit(HolidayEditViewModel hevm)
        {
            var err_msg  = string.Empty;
            var res_hevm = CreateViewModel <HolidayEditViewModel>();

            res_hevm.Holiday = hevm.Holiday;

            if (ModelState.IsValid)
            {
                try
                {
                    hevm.Holiday.EventStart = DateTime.ParseExact(hevm.Holiday.EventStartStr.Trim(), "dd.MM.yyyy", CultureInfo.InvariantCulture);
                }
                catch (Exception)
                {
                    ModelState.AddModelError("Holiday.EventStartStr", ViewResources.SharedStrings.CommonDateFormat);
                }
            }
            if (ModelState.IsValid)
            {
                try
                {
                    _holidayService.EditHoliday((int)hevm.Holiday.Id, hevm.Holiday.Name, _currentUser.Get().LoginName, hevm.Holiday.EventStart, hevm.Holiday.EventEnd);//, holiday.MovingHoliday);
                }
                catch (Exception ex)
                {
                    err_msg = ex.Message;
                    ModelState.AddModelError("", err_msg);
                }
            }
            if (ModelState.IsValid)
            {
                if (hevm.AllBuildings)
                {
                    var list = _HolidayBuildingRepository.FindAll().Where(x => x.HoliDayId == hevm.Holiday.Id).Select(x => x.BuildingId);
                    foreach (int ids in list)
                    {
                        _holidayBuildingService.DeleteHolidayBuilding(hevm.Holiday.Id.GetValueOrDefault(), ids);
                    }
                }
                else
                {
                    foreach (var build in hevm.BuildingItems.Where(x => x.Selected))
                    {
                        _holidayBuildingService.CreateHolidayBuilding(hevm.Holiday.Id.GetValueOrDefault(), Convert.ToInt32(build.Value));
                    }
                    foreach (var build in hevm.BuildingItems.Where(x => !x.Selected))
                    {
                        _holidayBuildingService.DeleteHolidayBuilding(hevm.Holiday.Id.GetValueOrDefault(), Convert.ToInt32(build.Value));
                    }
                }
            }
            return(Json(new
            {
                IsSucceed = ModelState.IsValid,
                Msg = ModelState.IsValid ? string.Format("{0} \"{1}\" ...", ViewResources.SharedStrings.HolidaysHolidaySaving, hevm.Holiday.Name) : err_msg,
                DisplayMessage = !string.IsNullOrEmpty(err_msg),
                viewData = ModelState.IsValid ? null : this.RenderPartialView("Edit", res_hevm)
            }));
        }
Exemple #2
0
        public async Task <ActionResult> Edit(EditHolidayViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                bool isSuccess = await _holidayService.EditHoliday(viewModel);

                if (isSuccess)
                {
                    _logger.Info($"Holiday ID {viewModel.Id} created successfully");
                    return(RedirectToAction("Index"));
                }
            }
            return(View(viewModel));
        }