Example #1
0
        public static string ExportUserPurchasesByType(VaporStoreDbContext context, string storeType)
        {
            var purchaseType = Enum.Parse <PurchaseType>(storeType);

            var users = context.Users
                        .Where(u => u.Cards.Any(c => c.Purchases.Count > 0))
                        .ToList()
                        .Select(u => new UserOutputModel()
            {
                Username  = u.Username,
                Purchases = context
                            .Purchases
                            .Where(p => p.Card.User.Username == u.Username && p.Type == purchaseType)
                            .OrderBy(p => p.Date)
                            .ToList()
                            .Select(p => new PurchaseOutputModel()
                {
                    Card = p.Card.Number,
                    Cvc  = p.Card.Cvc,
                    Date = p.Date.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture),
                    Game = new GameOutputModel()
                    {
                        Title = p.Game.Name,
                        Genre = p.Game.Genre.Name,
                        Price = p.Game.Price
                    }
                })
                            .ToList(),
                TotalSpent = context
                             .Purchases
                             .Where(p => p.Card.User.Username == u.Username &&
                                    p.Type == purchaseType)
                             .ToList()
                             .Sum(p => p.Game.Price)
            })
                        .Where(u => u.Purchases.Count > 0)
                        .OrderByDescending(u => u.TotalSpent)
                        .ThenBy(u => u.Username)
                        .ToList();

            var result = XMLConverter.Serialize(users, "Users");

            return(result);
        }
Example #2
0
        public static string ExportUserPurchasesByType(VaporStoreDbContext context, string storeType)
        {
            PurchaseType purchaseTypeEnum = Enum.Parse <PurchaseType>(storeType);

            var users = context
                        .Users
                        .ToArray()
                        .Where(u => u.Cards.Any(c => c.Purchases.Any()))
                        .Select(u => new ExportUserDTO()
            {
                Username  = u.Username,
                Purchases = context
                            .Purchases
                            .ToArray()
                            .Where(p => p.Card.User.Username == u.Username && p.Type == purchaseTypeEnum)
                            .OrderBy(p => p.Date)
                            .Select(p => new ExportUserPurchaseDTO()
                {
                    CardNumber = p.Card.Number,
                    CardCvc    = p.Card.Cvc,
                    Date       = p.Date.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture),
                    Game       = new ExportUserPurchaseGameDTO()
                    {
                        Name  = p.Game.Name,
                        Genre = p.Game.Genre.Name,
                        Price = p.Game.Price
                    }
                })
                            .ToArray(),
                TotalSpent = context
                             .Purchases
                             .ToArray()
                             .Where(p => p.Card.User.Username == u.Username && p.Type == purchaseTypeEnum)
                             .Sum(p => p.Game.Price)
            })
                        .Where(u => u.Purchases.Length > 0)
                        .OrderByDescending(u => u.TotalSpent)
                        .ThenBy(u => u.Username)
                        .ToArray();

            return(XMLConverter.Serialize(users, "Users"));
        }