public async Task <IActionResult> CreateHoliday(AddNewHolidayBindingModel bindingModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.SelectMany(v => v.Errors).Select(error => error.ErrorMessage))); } await this.CalendarService.CreateHoliday(bindingModel); return(Redirect("/")); }
public async Task <bool> CreateHoliday(AddNewHolidayBindingModel bindingModel) { var chosenDate = bindingModel.ChosenDate; var holidayName = bindingModel.HolidayName; var isPublic = bindingModel.IsPublicHoliday; var countryFromDb = dbContext.Countries.SingleOrDefault(s => s.Name == bindingModel.Country); var calendar = new Calendar(); calendar.CountryId = countryFromDb.Id; calendar.ChosenDate = chosenDate; calendar.HolidayName = holidayName; calendar.IsPublicHoliday = isPublic; this.dbContext.Calendars.Add(calendar); int result = await this.dbContext.SaveChangesAsync(); return(result > 0); }