Наследование: System.Data.Objects.DataClasses.EntityObject
 public JsonResult RemoveWinner(Winner winner)
 {
     var selectedEvent = repository.Winners.Where(x => x.EventId == winner.EventId).Select(x => x.Event).FirstOrDefault();
     if (!HttpContext.User.Identity.Name.Equals(selectedEvent.Creator))
     {
         return this.Json(false);
     }
     repository.RemoveWinner(winner);
     return this.Json(true);
 }
 public void RemoveWinner(Winner winner)
 {
     context.UpdateDetachedEntity<Winner>(winner, x => x.EventId);
     context.Winners.DeleteObject(winner);
     context.SaveChanges();
 }
Пример #3
0
 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();
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Winners EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToWinners(Winner winner)
 {
     base.AddObject("Winners", winner);
 }
 /// <summary>
 /// Create a new Winner object.
 /// </summary>
 /// <param name="eventId">Initial value of the EventId property.</param>
 /// <param name="userEmail">Initial value of the UserEmail property.</param>
 /// <param name="numberOfSpotsWon">Initial value of the NumberOfSpotsWon property.</param>
 /// <param name="catogoryId">Initial value of the CatogoryId property.</param>
 public static Winner CreateWinner(global::System.Int32 eventId, global::System.String userEmail, global::System.Int32 numberOfSpotsWon, global::System.Int32 catogoryId)
 {
     Winner winner = new Winner();
     winner.EventId = eventId;
     winner.UserEmail = userEmail;
     winner.NumberOfSpotsWon = numberOfSpotsWon;
     winner.CatogoryId = catogoryId;
     return winner;
 }
Пример #6
0
        public bool NotifyWinner(Winner winner)
        {
            var body = "<h1>Congratulations!</h1><br />";
            body += string.Format("You've won <strong>{0}</strong> {2} in the raffle for event: <strong>{1}</strong> <br />",
                winner.NumberOfSpotsWon, winner.Event.Name, winner.NumberOfSpotsWon == 1 ? "ticket" : "tickets");
            body += string.Format("Please look at the event details or contact <a href=\"{0}\">{0}</a> to get {1}.",
                winner.Event.Creator, winner.NumberOfSpotsWon == 1 ? "it" : "them");

            var mailMessage = new MailMessage {
                    From = new MailAddress(emailSettings.MailFromAddress),
                    Subject = string.Format("[CapRaffle] {0} winner!", winner.Event.Name),
                    Body = body,
                    IsBodyHtml = true
                };
            mailMessage.To.Add(new MailAddress(winner.UserEmail));

            var calendarData = GenerateCalendarEvent(winner.Event);

            using (var memoryStream = new MemoryStream(Encoding.Default.GetBytes(calendarData)))
            {
                mailMessage.Attachments.Add(new Attachment(memoryStream, "event.vcs"));
            }
            if (emailSettings.WriteAsFile)
            {
                mailMessage.BodyEncoding = Encoding.ASCII;
            }
            return SendEmail(mailMessage);
        }