public ActionResult CreateBasedOnOldEvent(int id) { var selectedEvent = eventRepository.Events.Where(x => x.EventId == id).FirstOrDefault(); var newevent = new Event(); if (selectedEvent != null) { var currentDatetime = DateTime.Now; newevent.DeadLine = new DateTime(currentDatetime.Year, currentDatetime.Month, currentDatetime.Day, currentDatetime.Hour, 0, 0).AddHours(1); newevent.StartTime = new DateTime(currentDatetime.Year, currentDatetime.Month, currentDatetime.Day, currentDatetime.Hour, 0, 0).AddHours(8); newevent.Name = selectedEvent.Name; newevent.AvailableSpots = selectedEvent.AvailableSpots; newevent.InformationUrl = selectedEvent.InformationUrl; newevent.Description = selectedEvent.Description; newevent.Category = selectedEvent.Category; } var model = new EventViewModel { SelectedEvent = newevent, Categories = categorySelectList() }; ViewBag.action = "Create"; return View("EventForm", model); }
public ActionResult Create() { int categories = eventRepository.Categories.Where(x => x.IsActive == true).Count(); if (categories == 0) { this.Error(string.Format("You cannot create a new event because there are no active categories")); return RedirectToAction("Index"); } else { var newevent = new Event(); //set proposed deadline to next full hour var currentDatetime = DateTime.Now; newevent.DeadLine = new DateTime(currentDatetime.Year, currentDatetime.Month, currentDatetime.Day, currentDatetime.Hour, 0, 0).AddHours(1); newevent.StartTime = new DateTime(currentDatetime.Year, currentDatetime.Month, currentDatetime.Day, currentDatetime.Hour, 0, 0).AddHours(8); var model = new EventViewModel { SelectedEvent = newevent, Categories = categorySelectList() }; ViewBag.action = "Create"; return View("EventForm", model); } }
public bool NotifyCreator(Event selectedEvent) { var body = "<h1>CapRaffle results</h1><br />"; body += "<h3>Winners</h3><br />"; if (selectedEvent.Winners.Count > 0) body += GetWinnerTable(selectedEvent.Winners); else body += "There was no winners for this event"; body += "<br />"; body += "An email has also been sent to all participants of this event"; var mailMessage = new MailMessage { From = new MailAddress(emailSettings.MailFromAddress), Subject = string.Format("[CapRaffle] {0} result", selectedEvent.Name), Body = body, IsBodyHtml = true }; mailMessage.To.Add(new MailAddress(selectedEvent.Creator)); if (emailSettings.WriteAsFile) { mailMessage.BodyEncoding = Encoding.ASCII; } return SendEmail(mailMessage); }
/// <summary> /// Create a new Event object. /// </summary> /// <param name="eventId">Initial value of the EventId property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="created">Initial value of the Created property.</param> /// <param name="creator">Initial value of the Creator property.</param> /// <param name="availableSpots">Initial value of the AvailableSpots property.</param> /// <param name="deadLine">Initial value of the DeadLine property.</param> /// <param name="categoryId">Initial value of the CategoryId property.</param> /// <param name="startTime">Initial value of the StartTime property.</param> /// <param name="isAutomaticDrawing">Initial value of the IsAutomaticDrawing property.</param> public static Event CreateEvent(global::System.Int32 eventId, global::System.String name, global::System.DateTime created, global::System.String creator, global::System.Int32 availableSpots, global::System.DateTime deadLine, global::System.Int32 categoryId, global::System.DateTime startTime, global::System.Boolean isAutomaticDrawing) { Event @event = new Event(); @event.EventId = eventId; @event.Name = name; @event.Created = created; @event.Creator = creator; @event.AvailableSpots = availableSpots; @event.DeadLine = deadLine; @event.CategoryId = categoryId; @event.StartTime = startTime; @event.IsAutomaticDrawing = isAutomaticDrawing; return @event; }
/// <summary> /// Deprecated Method for adding a new object to the Events EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToEvents(Event @event) { base.AddObject("Events", @event); }
public void DeleteEvent(Event selectedEvent) { context.Events.DeleteObject(selectedEvent); context.SaveChanges(); }
public void SaveEvent(Event changedEvent) { if (changedEvent.EventId == 0) { context.AddToEvents(changedEvent); } else { context.UpdateDetachedEntity<Event>(changedEvent, x => x.EventId); } context.SaveChanges(); }
public void setup() { //Arrange var mockHttpContext = new Mock<ControllerContext>(); mockHttpContext.SetupGet(p => p.HttpContext.User.Identity.Name).Returns("creator 2"); mockHttpContext.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true); mock = new Mock<IEventRepository>(); mock.Setup(m => m.Events).Returns(new Event[] { new Event { EventId = 1, Name = "event 1", Created = DateTime.Now, Creator = "creator 1", AvailableSpots = 2, DeadLine = DateTime.Now, CategoryId = 1 }, new Event { EventId = 2, Name = "event 2", Created = DateTime.Now, Creator = "creator 2", AvailableSpots = 2, DeadLine = DateTime.Now, CategoryId = 2 }, new Event { EventId = 3, Name = "event 3", Created = DateTime.Now, Creator = "creator 3", AvailableSpots = 2, DeadLine = DateTime.Now, CategoryId = 3 }, new Event { EventId = 4, Name = "event 4", Created = DateTime.Now, Creator = "creator 4", AvailableSpots = 2, DeadLine = DateTime.Now, CategoryId = 4 }, new Event { EventId = 5, Name = "event 5", Created = DateTime.Now, Creator = "creator 5", AvailableSpots = 2, DeadLine = DateTime.Now, CategoryId = 5 } }.AsQueryable()); mock.Setup(m => m.Categories).Returns(new Category[] { new Category { CategoryId = 1, Name = "Category1", IsActive = true }, new Category { CategoryId = 2, Name = "Category2", IsActive = true }, new Category { CategoryId = 3, Name = "Category3", IsActive = true }, new Category { CategoryId = 4, Name = "Category4", IsActive = true }, new Category { CategoryId = 5, Name = "Category5", IsActive = true } }.AsQueryable()); newevent = new Event { EventId = 10, Name = "CanCreateNewEvents", Created = DateTime.Now, Creator = "CanCreateNewEventsTest", AvailableSpots = 2, DeadLine = DateTime.Now, CategoryId = 10 }; IEnumerable<SelectListItem> categories = mock.Object.Categories.ToList().Select(x => new SelectListItem { Text = x.Name, Value = x.CategoryId.ToString() } ); categories.FirstOrDefault().Selected = true; selectedEvent = new EventViewModel { SelectedEvent = newevent, Categories = categories }; controller = new EventController(mock.Object); controller.ControllerContext = new ControllerContext(mockHttpContext.Object.HttpContext, new RouteData(), controller); }
private static string GenerateCalendarEvent(Event winnerEvent) { var calendarData = new StringWriter(); calendarData.WriteLine("BEGIN:VCALENDAR"); calendarData.WriteLine("VERSION:2.0"); calendarData.WriteLine("PRODID:-//hacksw/handcal//NONSGML v1.0//EN"); calendarData.WriteLine("BEGIN:VEVENT"); calendarData.WriteLine("DTSTAMP:{0}", ToCalendarDateString(winnerEvent.Created.ToUniversalTime())); calendarData.WriteLine("ORGANIZER:mailto:{0}", winnerEvent.Creator); calendarData.WriteLine("DTSTART:{0}", ToCalendarDateString(winnerEvent.StartTime.ToUniversalTime())); calendarData.WriteLine("SUMMARY:{0}", winnerEvent.Name); calendarData.WriteLine("END:VEVENT"); calendarData.WriteLine("END:VCALENDAR"); return calendarData.ToString(); }