예제 #1
0
        public IActionResult DeleteSeries(string id)
        {
            if (!ObjectId.TryParse(id, out _))
            {
                return(NotFound());
            }

            User user = _userService.UserFromContext(HttpContext);

            if (!user.Role.HasFlag(TradeSaberRole.Admin))
            {
                return(Unauthorized());
            }
            Series series = _cardDispatcher.GetSeries(id);

            if (series != null)
            {
                Card[] associatedCards = _cardDispatcher.GetCardsFromSeries(series.Id);
                for (int i = 0; i < associatedCards.Length; i++)
                {
                    _cardDispatcher.Delete(associatedCards[i]);
                }
                _cardDispatcher.Delete(series);
                return(NoContent());
            }
            return(NotFound());
        }
예제 #2
0
        public IActionResult DeletePack(string id)
        {
            if (!ObjectId.TryParse(id, out _))
            {
                return(NotFound());
            }

            User user = _userService.UserFromContext(HttpContext);

            if (!user.Role.HasFlag(TradeSaberRole.Admin))
            {
                return(Unauthorized());
            }
            Pack pack = _cardDispatcher.GetPack(id);

            if (pack != null)
            {
                User[] users = _userService.UsersWithPack(pack.Id);
                for (int i = 0; i < users.Length; i++)
                {
                    User u = users[i];
                    u.UnopenedPacks.RemoveAll(p => p == pack.Id);
                    _userService.Update(u);
                }
                _cardDispatcher.Delete(pack);
            }
            return(NoContent());
        }