public IActionResult UpdateNameDates(NameDatesCreateUpdateViewModel viewmodel) { if (string.IsNullOrWhiteSpace(viewmodel.Name)) { return(RedirectToAction("UpdateConvention", new { conId = viewmodel.Id, activeTab = "days", errorMessage = "הוזן שם כנס ריק" })); } var deletedFiltered = ParseDays(viewmodel.Days.Where(x => x.IsDeleted).ToList()); var nonDeletedFiltered = ParseDays(viewmodel.Days.Where(x => x.IsDeleted == false).ToList()); if (nonDeletedFiltered.Any() == false) { return(RedirectToAction("UpdateConvention", new { conId = viewmodel.Id, activeTab = "days", errorMessage = "לא הוזנו ימים לכנס" })); } if (nonDeletedFiltered.GroupBy(x => x.Date).Any(x => x.Count() > 1)) { return(RedirectToAction("UpdateConvention", new { conId = viewmodel.Id, activeTab = "days", errorMessage = "הוזן אותו התאריך יותר מפעם אחת" })); } try { var builder = Builder.LoadConvention(viewmodel.Id); foreach (var parsedDay in nonDeletedFiltered) { if (builder.Days.IsDaysExists(parsedDay.Date) == false) { builder.Days.AddDay(parsedDay.Date, parsedDay.StartTime, parsedDay.EndTime); } else { builder.Days.UpdateDay(parsedDay.Date, parsedDay.StartTime, parsedDay.EndTime); } builder.Days.SetTimeSlotStrategy(parsedDay.Date, viewmodel.TimeStrategy); } foreach (var parsedDay in deletedFiltered) { if (nonDeletedFiltered.Any(x => x.Date == parsedDay.Date) == false) { if (builder.Days.IsDaysExists(parsedDay.Date)) { builder.Days.RemoveDay(parsedDay.Date); } } } builder.SetTimeSlotStrategy(viewmodel.TimeStrategy); builder.ChangeName(viewmodel.Name); builder.AddExtraDetails(viewmodel.Location, viewmodel.TagLine); builder.Save(); } catch (Exception e) { return(RedirectToAction("UpdateConvention", new { conId = viewmodel.Id, activeTab = "days", errorMessage = e.Message })); } return(RedirectToAction("UpdateConvention", new { conId = viewmodel.Id, activeTab = "days", })); }