public ActionResult CreateEvent(Event newEvent) { var service = new Service(); if (newEvent.Min.HasValue && newEvent.Max.HasValue && (newEvent.Max.Value < newEvent.Min.Value)) { ModelState.AddModelError("Error", "Min can't be higher than max"); } else if (!service.ValidationOfTimeOfEvent(newEvent)) { ModelState.AddModelError("Time of event", "Date of event is not valid"); } else if (ModelState.IsValid) { newEvent.Active = true; newEvent.CreationTime = DateTime.Now; newEvent.OwnerId = service.GetUser(User.Identity.Name).UserID; if (service.CreateEvent(ref newEvent)) { return RedirectToAction("Index"); } else { ModelState.AddModelError("Error", "An error occured when creating your event, please try again later."); } } return View(newEvent); }
private void DisplayWelcomeMessage(User user) { Service service = new Service(); Event welcomeMessage = new Event(); welcomeMessage.Active = true; welcomeMessage.CreationTime = DateTime.Now; welcomeMessage.Description = "Welcome to doStuff, We are a event based social media! " + "You can make groups, events with friends! Here on the left is a plus sign which allows you to create a new event." + "To create a new group, please select the dropdown menu above! HAVE FUN! :)"; welcomeMessage.Location = "doStuff();"; welcomeMessage.Max = 1; welcomeMessage.Min = 1; welcomeMessage.Minutes = 11; welcomeMessage.Name = "Welcome!"; welcomeMessage.OwnerId = user.UserID; welcomeMessage.Photo = "random"; welcomeMessage.TimeOfEvent = DateTime.Now + new TimeSpan(0, welcomeMessage.Minutes, 0); service.CreateEvent(ref welcomeMessage); service.AnswerEvent(user.UserID, welcomeMessage.EventID, false); }
public ActionResult CreateEvent(int groupId, Event newEvent) { ViewBag.groupId = groupId; var service = new Service(); User user = service.GetUser(User.Identity.Name); if (service.IsMemberOfGroup(user.UserID, groupId) == false) { ModelState.AddModelError("Error", "Either the group doesn't exist or you do not have access to it."); return View(); } else if (newEvent.Min.HasValue && newEvent.Max.HasValue && (newEvent.Max.Value < newEvent.Min.Value)) { ModelState.AddModelError("Error", "Min can't be higher than max"); } else if (!service.ValidationOfTimeOfEvent(newEvent)) { ModelState.AddModelError("Time of event", "Date of event is not valid"); } else if (ModelState.IsValid) { newEvent.OwnerId = user.UserID; newEvent.CreationTime = DateTime.Now; newEvent.Active = true; if (service.CreateEvent(ref newEvent)) { return RedirectToAction("Index", new { groupId = groupId }); } ModelState.AddModelError("Error", "Something went wrong when trying to add your event to the group, please try again later."); return View(); } return View(); }