Esempio n. 1
0
        public async Task <SnackShopPurchase> GetSnackShopPurchaseById(int portalId, int sourceId,
                                                                       int snackShopPurchaseId,
                                                                       SnackShopPurchaseSource source)
        {
            IQueryable <SnackShopPurchase> snackShopPurchaseQuery =
                Context.SnackShopPurchases.Where(x =>
                                                 x.PortalId == portalId && !x.IsDeleted && x.IsActive && x.Id == snackShopPurchaseId &&
                                                 x.SnackShopItem.IsActive &&
                                                 !x.SnackShopItem.IsDeleted);

            snackShopPurchaseQuery = source switch
            {
                SnackShopPurchaseSource.Camper => snackShopPurchaseQuery.Where(x => x.CamperId == sourceId),
                SnackShopPurchaseSource.Counselor => snackShopPurchaseQuery.Where(x => x.CounselorId == sourceId),
                _ => throw new ArgumentOutOfRangeException(nameof(source), source, "The source is required.")
            };

            SnackShopPurchase snackShopPurchase = await snackShopPurchaseQuery.FirstOrDefaultAsync();

            if (snackShopPurchase == null)
            {
                throw new Exception("This snack shop purchase does not exist.");
            }

            return(snackShopPurchase);
        }
Esempio n. 2
0
        public async Task <IEnumerable <SnackShopPurchase> > GetSnackShopPurchases(int portalId, int sourceId,
                                                                                   SnackShopPurchaseSource source)
        {
            IQueryable <SnackShopPurchase> snackShopPurchases =
                Context.SnackShopPurchases.Where(x =>
                                                 x.PortalId == portalId && !x.IsDeleted && x.IsActive && x.SnackShopItem.IsActive &&
                                                 !x.SnackShopItem.IsDeleted);

            snackShopPurchases = source switch
            {
                SnackShopPurchaseSource.Camper => snackShopPurchases.Where(x => x.CamperId == sourceId),
                SnackShopPurchaseSource.Counselor => snackShopPurchases.Where(x => x.CounselorId == sourceId),
                _ => throw new ArgumentOutOfRangeException(nameof(source), source, "The source is required.")
            };

            return(await snackShopPurchases.ToListAsync());
        }