public ActionResult Add(Team team) { if (!String.IsNullOrWhiteSpace(team.TeamName)) { TeamsRepository teamsrep = new TeamsRepository(); if (teamsrep.GetAllTeams().Where(k => k.TeamName.ToLower() == team.TeamName.ToLower()).Count() > 0) { ModelState.AddModelError("TeamName", "That team name is already in use"); } else { teamsrep.Add(team); teamsrep.SaveChanges(); return(Redirect("/teams")); } } else { ModelState.AddModelError("TeamName", "Please enter a team name"); } return(View(team)); }
private void AddTeam(Team teamBdo) { var teamEntity = new TeamEntity() { SeasonId = _seasonId, WeekOffset = _weekOffset, PremierLeagueTeamId = teamBdo.id, TeamName = teamBdo.name, CreatedDateTimeUtc = DateTime.UtcNow }; // TODO: Exception handling. TeamsRepository.Create(teamEntity); TeamsRepository.SaveChanges(); var teamPlayers = GetTeamPlayers(teamBdo); _teamSequenceIndex = 0; foreach (var playerTypePair in _fantasyFootballBdo.PlayerTypes) { AddTeamPlayer(teamEntity, playerTypePair.Value, teamPlayers); } PlayersRepository.SaveChanges(); }
public ActionResult Add(Team team) { List <SelectListItem> venuelist = new List <SelectListItem>(); VenuesRepository VenuesRep = new VenuesRepository(); var myvenues = VenuesRep.GetAllVenues().OrderBy(k => k.Name); TeamsRepository teamsrep = new TeamsRepository(); //--- string fileName = Path.GetFileNameWithoutExtension(team.ImageUpload.FileName); // string extension = Path.GetExtension(team.ImageUpload.FileName); //fileName = fileName + DateTime.Now.ToString("yymmssff") + extension; // team.LogoUrl = "~/Content/images/" + fileName; // fileName = Path.Combine(Server.MapPath("~/Content/images/"), fileName); // team.ImageUpload.SaveAs(fileName); if (myvenues.Count() > 0) { foreach (Venue v in myvenues) { SelectListItem sli = new SelectListItem(); sli.Value = v.Id.ToString(); sli.Text = v.Name; venuelist.Add(sli); } } ViewData["Venues"] = venuelist; if (!String.IsNullOrWhiteSpace(team.Name)) { if (teamsrep.GetAllTeams().Where(k => k.Name.ToLower() == team.Name.ToLower()).Count() > 0) { ModelState.AddModelError("Name", "That team name is already in use"); } else { teamsrep.Add(team); teamsrep.SaveChanges(); return(Redirect("/teams")); } } else { //No team entered ModelState.AddModelError("Name", "Please enter team name"); } return(View(team)); }
public async Task <IActionResult> OnGet(int invitationId, string email, string returnUrl = null) { // Return if invitation is already accepted Invitation invitation = InvitationsRepository.SearchFor(x => x.Id == invitationId).Include("User").Include("Event").FirstOrDefault(); if (invitation.InvitationAccepted) { // Display page? return(RedirectToAction("Index", "Home")); } ApplicationUser invitee = await _userManager.FindByEmailAsync(email); if (invitee == null) { // If user doesn't exist, redirect to Register page return(RedirectToPage("/Account/Register", new { area = "Identity", returnUrl })); } DinnerEvent dinnerEvent = DinnerEventsRepository.GetById(invitation.Event.Id); EventParticipation inviteeParticipation = EventParticipationsRepository.SearchFor(x => x.User.Id == invitee.Id && x.Event.Id == invitation.Event.Id).FirstOrDefault(); if (inviteeParticipation == null) { inviteeParticipation = new EventParticipation { User = invitee, Event = dinnerEvent }; EventParticipationsRepository.Insert(inviteeParticipation); EventParticipationsRepository.SaveChanges(); } invitation.InvitationAccepted = true; InvitationsRepository.Update(invitation); // Check if user has more pending invitations and make them invalid var otherInvitations = InvitationsRepository.SearchFor(x => x.User.Id == invitee.Id); foreach (var otherInvitation in otherInvitations) { otherInvitation.InvitationAccepted = true; InvitationsRepository.Update(otherInvitation); } InvitationsRepository.SaveChanges(); // Add contact to Mailjet Contacts, save ContactId string apiKey = Configuration?.GetEmailSettings("apiKey"); string apiSecret = Configuration?.GetEmailSettings("apiSecret"); // Save list recipient id to database long listRecipientId = await EmailSender.AddContactToContactListAsync(apiKey, apiSecret, invitee.ContactId.ToString(CultureInfo.InvariantCulture), dinnerEvent.ContactList.ToString(CultureInfo.InvariantCulture)); invitee.ListRecipientId = listRecipientId; await _userManager.UpdateAsync(invitee); EventParticipation inviterParticipation = EventParticipationsRepository.SearchFor(x => x.User.Id == invitation.User.Id && x.Event.Id == invitation.Event.Id).FirstOrDefault(); // Create a new team Team newTeam = new Team { Partner1 = invitation.User, Partner2 = invitee, SelectedCourse = inviterParticipation?.SelectedCourse, AddressStreet = inviterParticipation.Address, AddressNumber = inviterParticipation.AddressNumber, FullAddress = inviterParticipation.Address + " " + inviterParticipation.AddressNumber, AddressAdditions = inviterParticipation.AddressAdditions, Phone = inviterParticipation.Phone, DinnerSaver = inviterParticipation.DinnerSaver, Event = invitation.Event, Allergies = inviterParticipation.Allergies, City = dinnerEvent.City }; TeamsRepository.Insert(newTeam); TeamsRepository.SaveChanges(); // Send the email await EmailSender.SendMailjetAsync(apiKey, apiSecret, 1197519, "Deine Einladung wurde angenommen", "*****@*****.**", "Das Großstadt Dinner Team", invitation.User.FirstName, invitation.User.Email, invitation.User.FirstName + " " + invitation.User.LastName, "", invitee.FirstName, invitation.Event.EventName, invitation.Event.EventDate.ToShortDateString()); TempData["StatusMessage"] = @"Du hast die Einladung erfolgreich angenommen. Die Teamdaten deines Partners wurden übernommen. Ihr seid nun vollständig angemeldet."; return(RedirectToPage("./RegistrationData")); }
/// <summary> /// Unregister from event method. /// </summary> /// <returns></returns> public async Task <IActionResult> OnGetEventUnregister() { if (HttpContext.Session.GetString("EventId") == null) { string returnUrl = HttpContext.Request.Path.ToString(); return(RedirectToPage("/Account/Login", new { area = "Identity", returnUrl })); } var eventId = int.Parse(HttpContext.Session.GetString("EventId"), CultureInfo.CurrentCulture); var dinnerEvent = DinnerEventsRepository.GetById(eventId); var user = await UserManager.GetUserAsync(HttpContext.User); EventParticipation eventParticipation = EventParticipationsRepository.SearchFor(x => x.User == user && x.Event == dinnerEvent).FirstOrDefault(); EventParticipationsRepository.Delete(eventParticipation); EventParticipationsRepository.SaveChanges(); Team team = TeamsRepository.SearchFor(x => x.Event.Id == dinnerEvent.Id && (x.Partner1.Id == user.Id || x.Partner2.Id == user.Id)).Include("Partner1").Include("Partner2").FirstOrDefault(); // Remove team if (team != null) { if (dinnerEvent.RoutesOpen) { // Delete from existing routes var routes = RoutesRepository.SearchFor(x => x.Event.Id == eventId && x.RouteForTeam.Id == team.Id) .Include(a => a.Event) .Include(a => a.RouteForTeam) .Include(a => a.FirstCourseHostTeam).ThenInclude(b => b.Partner1) .Include(a => a.FirstCourseHostTeam).ThenInclude(b => b.Partner2) .Include(a => a.FirstCourseGuestTeam1).ThenInclude(b => b.Partner1) .Include(a => a.FirstCourseGuestTeam1).ThenInclude(b => b.Partner2) .Include(a => a.FirstCourseGuestTeam2).ThenInclude(b => b.Partner1) .Include(a => a.FirstCourseGuestTeam2).ThenInclude(b => b.Partner2) .Include(a => a.SecondCourseHostTeam).ThenInclude(b => b.Partner1) .Include(a => a.SecondCourseHostTeam).ThenInclude(b => b.Partner2) .Include(a => a.SecondCourseGuestTeam1).ThenInclude(b => b.Partner1) .Include(a => a.SecondCourseGuestTeam1).ThenInclude(b => b.Partner2) .Include(a => a.SecondCourseGuestTeam2).ThenInclude(b => b.Partner1) .Include(a => a.SecondCourseGuestTeam2).ThenInclude(b => b.Partner2) .Include(a => a.ThirdCourseHostTeam).ThenInclude(b => b.Partner1) .Include(a => a.ThirdCourseHostTeam).ThenInclude(b => b.Partner2) .Include(a => a.ThirdCourseGuestTeam1).ThenInclude(b => b.Partner1) .Include(a => a.ThirdCourseGuestTeam1).ThenInclude(b => b.Partner2) .Include(a => a.ThirdCourseGuestTeam2).ThenInclude(b => b.Partner1) .Include(a => a.ThirdCourseGuestTeam2).ThenInclude(b => b.Partner2); foreach (var route in routes) { if (route.RouteForTeam.Id == team.Id) { route.RouteForTeam = null; } if (route.FirstCourseHostTeam.Id == team.Id) { route.FirstCourseHostTeam = null; } if (route.FirstCourseGuestTeam1.Id == team.Id) { route.FirstCourseGuestTeam1 = null; } if (route.FirstCourseGuestTeam2.Id == team.Id) { route.FirstCourseGuestTeam2 = null; } if (route.SecondCourseHostTeam.Id == team.Id) { route.SecondCourseHostTeam = null; } if (route.SecondCourseGuestTeam1.Id == team.Id) { route.SecondCourseGuestTeam1 = null; } if (route.SecondCourseGuestTeam2.Id == team.Id) { route.SecondCourseGuestTeam2 = null; } if (route.ThirdCourseHostTeam.Id == team.Id) { route.ThirdCourseHostTeam = null; } if (route.ThirdCourseGuestTeam1.Id == team.Id) { route.ThirdCourseGuestTeam1 = null; } if (route.ThirdCourseGuestTeam2.Id == team.Id) { route.ThirdCourseGuestTeam2 = null; } RoutesRepository.Update(route); } RoutesRepository.SaveChanges(); } // Remove contact from contact list string apiKey = Configuration?.GetEmailSettings("apiKey"); string apiSecret = Configuration?.GetEmailSettings("apiSecret"); if (team.Partner1 != null) { await EmailSender.RemoveListRecipientAsync(apiKey, apiSecret, team.Partner1.ListRecipientId); } if (team.Partner2 != null) { await EmailSender.RemoveListRecipientAsync(apiKey, apiSecret, team.Partner2.ListRecipientId); } TeamsRepository.Delete(team); TeamsRepository.SaveChanges(); TempData["StatusMessage"] = "Du hast dein Team vom Event abgemeldet."; } else { TempData["StatusMessage"] = "Du hast dich vom Event abgemeldet."; } return(RedirectToPage("RegistrationData", new { id = eventId })); }
public async Task <IActionResult> OnPostAsync() { if (HttpContext.Session.GetString("EventId") == null) { string returnUrl = HttpContext.Request.Path.ToString(); return(RedirectToPage("/Account/Login", new { area = "Identity", returnUrl })); } ViewData["IsParticipating"] = HttpContext.Session.GetString("IsParticipating"); int eventId = int.Parse(HttpContext.Session.GetString("EventId"), CultureInfo.CurrentCulture); DinnerEvent dinnerEvent = DinnerEventsRepository.GetById(eventId); if (dinnerEvent != null) { // Values are passed-through to layout page ViewData["EventName"] = dinnerEvent.EventName; ViewData["EventDate"] = dinnerEvent.EventDate.ToShortDateString(); ViewData["EventCity"] = dinnerEvent.City; ViewData["EventPictureLink"] = dinnerEvent.EventPictureLink; } if (!ModelState.IsValid) { return(Page()); } var user = await UserManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{UserManager.GetUserId(User)}'."); } // Load Team Team team = TeamsRepository.SearchFor(x => x.Event.Id == dinnerEvent.Id && (x.Partner1.Id == user.Id || x.Partner2.Id == user.Id)).Include("Partner1").Include("Partner2").Include("Event").FirstOrDefault(); if (team != null) { team.DinnerSaver = Input.DinnerSaver; team.SelectedCourse = Input.SelectedCourse; team.AddressStreet = Input.AddressStreet; team.AddressAdditions = Input.AddressAdditions; team.AddressNumber = Input.AddressNumber; team.FullAddress = Input.AddressStreet + " " + Input.AddressNumber; TeamsRepository.Update(team); TeamsRepository.SaveChanges(); TempData["StatusMessage"] = @"Die Einstellungen für dein Team wurden gespeichert."; } else { EventParticipation participation = EventParticipationsRepository.SearchFor(x => x.User.Id == user.Id && x.Event.Id == eventId).FirstOrDefault(); if (participation == null) { participation = new EventParticipation { InvitationMailSent = true, User = user, Event = dinnerEvent, PartnerName = Input.PartnerFirstName, PartnerLastName = Input.PartnerLastName, PartnerEmail = Input.PartnerEmail, Address = Input.AddressStreet, AddressNumber = Input.AddressNumber, AddressAdditions = Input.AddressAdditions, Phone = Input.Phone, Allergies = Input.Allergies, SelectedCourse = Input.SelectedCourse, IsWithoutPartner = Input.IsWithoutPartner, DinnerSaver = Input.DinnerSaver, RegistrationComplete = true }; EventParticipationsRepository.Insert(participation); EventParticipationsRepository.SaveChanges(); // Add contact to Mailjet Contacts, save ContactId string apiKey = Configuration?.GetEmailSettings("apiKey"); string apiSecret = Configuration?.GetEmailSettings("apiSecret"); long listRecipientId = await EmailSender.AddContactToContactListAsync(apiKey, apiSecret, user.ContactId.ToString(CultureInfo.InvariantCulture), dinnerEvent.ContactList.ToString(CultureInfo.InvariantCulture)); user.ListRecipientId = listRecipientId; await UserManager.UpdateAsync(user); } else { participation.Phone = Input.Phone; participation.Allergies = Input.Allergies; participation.Address = Input.AddressStreet; participation.AddressNumber = Input.AddressNumber; participation.AddressAdditions = Input.AddressAdditions; participation.PartnerName = Input.PartnerFirstName; participation.PartnerLastName = Input.PartnerLastName; participation.PartnerEmail = Input.PartnerEmail; participation.SelectedCourse = Input.SelectedCourse; participation.IsWithoutPartner = Input.IsWithoutPartner; participation.DinnerSaver = Input.DinnerSaver; participation.RegistrationComplete = true; EventParticipationsRepository.Update(participation); EventParticipationsRepository.SaveChanges(); } await OnPostSendPartnerInvitation(eventId, Input.PartnerFirstName, Input.PartnerLastName, Input.PartnerEmail, user.Id); TempData["StatusMessage"] = "Deine Anmeldung wurde gespeichert. Eine Einladung wurde an " + Input.PartnerEmail + " geschickt. Die Anmeldung ist vollständig sobald dein Partner bestätigt hat."; } return(RedirectToPage("./RegistrationData", eventId)); }
public async Task <IActionResult> OnPostAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } RequirePassword = await _userManager.HasPasswordAsync(user); if (RequirePassword) { if (!await _userManager.CheckPasswordAsync(user, Input.Password)) { ModelState.AddModelError(string.Empty, "Incorrect password."); return(Page()); } } // Remove contact from contact list string apiKey = Configuration?.GetEmailSettings("apiKey"); string apiSecret = Configuration?.GetEmailSettings("apiSecret"); Team team = TeamsRepository.SearchFor(x => x.Partner1.Id == user.Id || x.Partner2.Id == user.Id).Include("Partner1").Include("Partner2").FirstOrDefault(); if (team != null) { // Delete from existing routes var routes = RoutesRepository.SearchFor(x => x.RouteForTeam.Id == team.Id || x.FirstCourseHostTeam.Id == team.Id || x.FirstCourseGuestTeam1.Id == team.Id || x.FirstCourseGuestTeam2.Id == team.Id || x.SecondCourseHostTeam.Id == team.Id || x.SecondCourseGuestTeam1.Id == team.Id || x.SecondCourseGuestTeam2.Id == team.Id || x.ThirdCourseHostTeam.Id == team.Id || x.ThirdCourseGuestTeam1.Id == team.Id || x.ThirdCourseGuestTeam2.Id == team.Id) .Include(a => a.RouteForTeam) .Include(a => a.FirstCourseHostTeam) .Include(a => a.FirstCourseGuestTeam1) .Include(a => a.FirstCourseGuestTeam2) .Include(a => a.SecondCourseHostTeam) .Include(a => a.SecondCourseGuestTeam1) .Include(a => a.SecondCourseGuestTeam2) .Include(a => a.ThirdCourseHostTeam) .Include(a => a.ThirdCourseGuestTeam1) .Include(a => a.ThirdCourseGuestTeam2); foreach (var route in routes) { if (route.RouteForTeam.Id == team.Id) { route.RouteForTeam = null; } if (route.FirstCourseHostTeam.Id == team.Id) { route.FirstCourseHostTeam = null; } if (route.FirstCourseGuestTeam1.Id == team.Id) { route.FirstCourseGuestTeam1 = null; } if (route.FirstCourseGuestTeam2.Id == team.Id) { route.FirstCourseGuestTeam2 = null; } if (route.SecondCourseHostTeam.Id == team.Id) { route.SecondCourseHostTeam = null; } if (route.SecondCourseGuestTeam1.Id == team.Id) { route.SecondCourseGuestTeam1 = null; } if (route.SecondCourseGuestTeam2.Id == team.Id) { route.SecondCourseGuestTeam2 = null; } if (route.ThirdCourseHostTeam.Id == team.Id) { route.ThirdCourseHostTeam = null; } if (route.ThirdCourseGuestTeam1.Id == team.Id) { route.ThirdCourseGuestTeam1 = null; } if (route.ThirdCourseGuestTeam2.Id == team.Id) { route.ThirdCourseGuestTeam2 = null; } RoutesRepository.Update(route); } RoutesRepository.SaveChanges(); if (team.Partner1.Id == user.Id || team.Partner2.Id == user.Id) { if (team.Partner1 != null) { await _emailSender.RemoveListRecipientAsync(apiKey, apiSecret, team.Partner1.ListRecipientId); } if (team.Partner2 != null) { await _emailSender.RemoveListRecipientAsync(apiKey, apiSecret, team.Partner2.ListRecipientId); } TeamsRepository.Delete(team); TeamsRepository.SaveChanges(); } } // Delete participations var participations = EventParticipationsRepository.SearchFor(x => x.User.Id == user.Id).ToList(); foreach (var participation in participations) { EventParticipationsRepository.Delete(participation); EventParticipationsRepository.SaveChanges(); } // Delete invitations var invitations = InvitationsRepository.SearchFor(x => x.User.Id == user.Id).ToList(); foreach (var invitation in invitations) { InvitationsRepository.Delete(invitation); InvitationsRepository.SaveChanges(); } // Delete user from Mailjet contact lists await _emailSender.RemoveListRecipientAsync(apiKey, apiSecret, user.ListRecipientId); // Delete user var result = await _userManager.DeleteAsync(user); var userId = await _userManager.GetUserIdAsync(user); if (!result.Succeeded) { throw new InvalidOperationException($"Unexpected error occurred deleting user with ID '{userId}'."); } await _signInManager.SignOutAsync(); _logger.LogInformation("User with ID '{UserId}' deleted themselves.", userId); return(Redirect("~/")); }