public ActionResult Create(CreateEventViewModel eventViewModel) { if (ModelState.IsValid) { var createEvent = CreateEvent(eventViewModel); db.Events.Add(createEvent); db.SaveChanges(); return RedirectToAction("Index"); } return View(eventViewModel); }
public ActionResult Edit(CreateEventViewModel eventViewModel) { if (ModelState.IsValid) { var dbEvent = db.Events.Find(eventViewModel.EventId); var updateEvent = UpdateEvent(dbEvent, eventViewModel); db.Entry(updateEvent).State = EntityState.Modified; db.Entry(updateEvent.Address).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(eventViewModel); }
private Event UpdateEvent(Event eventModel, CreateEventViewModel eventViewModel) { eventModel.Address.City = eventViewModel.Address.City; eventModel.Address.HouseNumber = eventViewModel.Address.HouseNumber; eventModel.Address.StreetName = eventViewModel.Address.StreetName; eventModel.Address.Zip = eventViewModel.Address.Zip; eventModel.Date = eventViewModel.Date; eventModel.Time = eventViewModel.Time; eventModel.Description = eventViewModel.Description; eventModel.ReplyDeadline = eventViewModel.ReplyDeadline; eventModel.FirstReminderMail = eventViewModel.FirstReminderMail; eventModel.SecondReminderMail = eventViewModel.SecondReminderMail; eventModel.Title = eventViewModel.Title; eventModel.AcceptanceEvent = eventViewModel.AcceptanceEvent; eventModel.DateEdited = DateTime.Now; return eventModel; }
private Event CreateEvent(CreateEventViewModel eventViewModel) { var address = new Address { City = eventViewModel.Address.City, HouseNumber = eventViewModel.Address.HouseNumber, StreetName = eventViewModel.Address.StreetName, Zip = eventViewModel.Address.Zip }; var createEvent = new Event { DateCreated = DateTime.Now, Title = eventViewModel.Title, Description = eventViewModel.Description, DateEdited = DateTime.Now, Date = eventViewModel.Date, Time = eventViewModel.Time, ReplyDeadline = eventViewModel.ReplyDeadline, FirstReminderMail = eventViewModel.FirstReminderMail, SecondReminderMail = eventViewModel.SecondReminderMail, AcceptanceEvent = eventViewModel.AcceptanceEvent, Address = address, Participants = new List<Participant>() }; return createEvent; }