public IActionResult Post([FromBody] CreateHolidayDto newHoliday) { var result = _holidayService.CreateHoliday(newHoliday); if (!result.IsSuccess) { return(BadRequest(result)); } return(Ok(result.Response)); }
public ActionResult Create(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.CreateHoliday(hevm.Holiday.Name, _currentUser.Get().LoginName, hevm.Holiday.EventStart, hevm.Holiday.EventEnd, false); //hevm.Holiday.MovingHoliday); } catch (Exception ex) { err_msg = ex.Message; ModelState.AddModelError("", err_msg); } } return(Json(new { IsSucceed = ModelState.IsValid, Msg = ModelState.IsValid ? ViewResources.SharedStrings.DataSavingMessage : err_msg, DisplayMessage = !string.IsNullOrEmpty(err_msg), viewData = ModelState.IsValid ? null : this.RenderPartialView("Create", res_hevm) })); }