Esempio n. 1
0
        public ActionResult Delete(int id)
        {
            _teamsRepository.Delete(id);

            TempData["Message"] = "Your team was successfully deleted!";

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public ActionResult <string> Delete(int id)
        {
            bool successful = _tr.Delete(id);

            if (!successful)
            {
                return(BadRequest());
            }
            return(Ok());
        }
Esempio n. 3
0
        public string Delete(int id)
        {
            Team exists = _repo.Get(id);

            if (exists == null)
            {
                throw new Exception("Invalid Id");
            }
            _repo.Delete(id);
            return(" that teams been iced, eh");
        }
Esempio n. 4
0
        internal object Delete(string creatorId, int id)
        {
            var exists = _repo.GetById(id);

            if (exists == null)
            {
                throw new Exception("Invalid Id");
            }
            if (exists.CreatorId != creatorId)
            {
                throw new Exception("I can't let you do that");
            }
            _repo.Delete(id);
            return("Successfully deleted");
        }
Esempio n. 5
0
        public async Task DeletesTeam()
        {
            var mockTeams = new List <Team>
            {
                new Team {
                    Id = 1
                },
                new Team {
                    Id = 2
                },
                new Team {
                    Id = 3
                }
            };

            using (var context = new ApplicationDbContext(_options))
            {
                context.Teams.AddRange(mockTeams);

                context.SaveChanges();
            }

            using (var context = new ApplicationDbContext(_options))
            {
                var teamsRepository = new TeamsRepository(context);

                var team = mockTeams[0];
                await teamsRepository.Delete(team);
            }

            using (var context = new ApplicationDbContext(_options))
            {
                Assert.Equal(2, context.Teams.Count());
                Assert.Null(context.Teams.SingleOrDefault(x => x.Id == 1));
            }
        }
Esempio n. 6
0
        /// <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()
        {
            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("~/"));
        }