public ActionResult CreateEvents(List<StartEndModel> model) { var id = model.ElementAt(0).TrainingID; foreach (var item in model) { if (item.StartDate.Year != 1 && item.EndDate.Year != 1) { var users = new Event { TrainingID = id, StartDate = item.StartDate, EndDate = item.EndDate }; _store.SaveEvent(users); } } return RedirectToAction("EventsList"); }
public void SaveEvent(Event model) { if (model.ID == 0) _context.Events.Add(model); else { Event dbEntry = _context.Events.Find(model.ID); if (dbEntry != null) { dbEntry.StartDate = model.StartDate; dbEntry.EndDate = model.EndDate; } } _context.SaveChanges(); }