public ActionResult Create(UserEvent participant) { try { if (repository.Users.Where(x => x.Email.Equals(participant.UserEmail)).Count() == 0) { participant.UserEmail = participant.UserEmail.ToLower(); var name = participant.UserEmail; if (name.Contains(".") || name.Contains("-") || name.Contains(".")) { name = participant.UserEmail.Replace("capgemini.com", ""); name = name.Replace("-", " "); name = name.Replace(".", " "); name = name.Substring(0, name.Length - 1); name = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(name.ToLower()); } accountrepository.Create(participant.UserEmail, null, name); } repository.SaveParticipant(participant); } catch (Exception e) { this.Error(e.Message); } return RedirectToAction("GetParticipants", new { eventId = participant.EventId }); }
public JsonResult Delete(UserEvent participant) { if (!HttpContext.User.Identity.Name.Equals(participant.UserEmail)) { var selectedEvent = repository.Events.Where(x => x.EventId == participant.EventId).FirstOrDefault(); if (!HttpContext.User.Identity.Name.Equals(selectedEvent.Creator)) { return this.Json(false); } } repository.DeleteParticipant(participant); return this.Json(true); }
public bool NotifyLooser(UserEvent looser) { var body = "<h1>Sorry!</h1><br />"; body += string.Format("You did not win any tickets in the raffle for event: <strong>{0}</strong><br />", looser.Event.Name); body += "Better luck next time"; var mailMessage = new MailMessage { From = new MailAddress(emailSettings.MailFromAddress), Subject = string.Format("[CapRaffle] {0} result", looser.Event.Name), Body = body, IsBodyHtml = true }; mailMessage.To.Add(new MailAddress(looser.UserEmail)); if (emailSettings.WriteAsFile) { mailMessage.BodyEncoding = Encoding.ASCII; } return SendEmail(mailMessage); }
private void DeleteParticipant(UserEvent participant) { context.UserEvents.DeleteObject(participant); context.SaveChanges(); }
private void SaveWinner(UserEvent drawnParticipant, int numberOfSpotsGiven) { Winner winner = new Winner { EventId = drawnParticipant.EventId, UserEmail = drawnParticipant.UserEmail, Date = DateTime.Now, NumberOfSpotsWon = numberOfSpotsGiven, CatogoryId = context.Events.FirstOrDefault(x => x.EventId == eventId).CategoryId }; if (context.Winners.Where(x => x.EventId == winner.EventId && x.UserEmail == winner.UserEmail).Count() == 0) { context.AddToWinners(winner); } else { context.UpdateDetachedEntity<Winner>(winner, x => x.EventId); } context.SaveChanges(); }
public void setup() { //Arrange var mockHttpContext = new Mock<ControllerContext>(); mockHttpContext.SetupGet(p => p.HttpContext.User.Identity.Name).Returns("*****@*****.**"); 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 = "*****@*****.**", 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.Users).Returns(new User[] { new User { Email = "*****@*****.**", Name = "test", Password = "******" }, new User { Email = "*****@*****.**", Name = "atest", Password = "******" }, new User { Email = "*****@*****.**", Name = "aaatest", Password = "******" }, new User { Email = "*****@*****.**", Name = "btest", Password = "******" } }.AsQueryable()); mock.Setup(m => m.Participants).Returns(new UserEvent[] { new UserEvent { EventId = 1, UserEmail = "*****@*****.**", NumberOfSpots = 1 }, new UserEvent { EventId = 1, UserEmail = "*****@*****.**", NumberOfSpots = 1 }, new UserEvent { EventId = 1, UserEmail = "*****@*****.**", NumberOfSpots = 1 }, new UserEvent { EventId = 1, UserEmail = "*****@*****.**", NumberOfSpots = 1 } }.AsQueryable()); var accountmock = new Mock<IAccountRepository>(); participant = new UserEvent { EventId = 1, UserEmail = "*****@*****.**", NumberOfSpots = 1 }; controller = new ParticipantController(mock.Object, accountmock.Object); controller.ControllerContext = new ControllerContext(mockHttpContext.Object.HttpContext, new RouteData(), controller); }
/// <summary> /// Deprecated Method for adding a new object to the UserEvents EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToUserEvents(UserEvent userEvent) { base.AddObject("UserEvents", userEvent); }
/// <summary> /// Create a new UserEvent object. /// </summary> /// <param name="userEmail">Initial value of the UserEmail property.</param> /// <param name="eventId">Initial value of the EventId property.</param> /// <param name="numberOfSpots">Initial value of the NumberOfSpots property.</param> /// <param name="acceptLessSpots">Initial value of the AcceptLessSpots property.</param> public static UserEvent CreateUserEvent(global::System.String userEmail, global::System.Int32 eventId, global::System.Int32 numberOfSpots, global::System.Boolean acceptLessSpots) { UserEvent userEvent = new UserEvent(); userEvent.UserEmail = userEmail; userEvent.EventId = eventId; userEvent.NumberOfSpots = numberOfSpots; userEvent.AcceptLessSpots = acceptLessSpots; return userEvent; }
public void DeleteParticipant(UserEvent participant) { context.UpdateDetachedEntity<UserEvent>(participant, x => x.EventId); context.UserEvents.DeleteObject(participant); context.SaveChanges(); }
public void SaveParticipant(UserEvent participant) { if (DeadlineForEventHasPassed(participant.EventId)) { throw new ArgumentException("You cant create or edit a participation after the deadline"); } if (context.UserEvents.Where(x => x.EventId == participant.EventId && x.UserEmail.Equals(participant.UserEmail)).Count() == 0) { context.AddToUserEvents(participant); } else { context.UpdateDetachedEntity<UserEvent>(participant, x => x.EventId); } context.SaveChanges(); }