public async Task <IEnumerable <TransactionDto> > GetAllTransactions(int customerId)
 {
     try
     {
         var item = (await _rep.Get()).Where(b => b.CustomerId.Equals(customerId));
         var dtOs = Mapper.Map <IEnumerable <TransactionDto> >(item);
         return(dtOs);
     }
     catch (Exception e)
     {
         //Logger.ErrorException(e.Message, e);
         throw e;
     }
 }
        public async Task <IEnumerable <CustomerDto> > GetAllCustomers()
        {
            try
            {
                var item = await _rep.Get();

                var dtOs = Mapper.Map <IEnumerable <CustomerDto> >(item);
                return(dtOs);
            }
            catch (Exception e)
            {
                //Logger.ErrorException(e.Message, e);
                throw e;
            }
        }
Exemple #3
0
        public async Task <AllergenDto> Handle(GetAllergenQuery request, CancellationToken cancellationToken)
        {
            var entities = await _repository.Get(
                filter : source => source.Id == request.Id, cancellationToken : cancellationToken
                );

            return(_mapper.Map <AllergenDto>(entities));
        }
Exemple #4
0
 public async Task <Invoice> GetAllTransactions(string customerId)
 {
     try
     {
         var items   = (await _rep.Get()).Where(b => b.UserId.Equals(customerId)).ToList();
         var invoice = new Invoice
         {
             Transactions = items,
             TotalPoints  = items.Sum(c => c.Points),
             TotalPrice   = items.Sum(c => c.Price)
         };
         return(invoice);
     }
     catch (Exception e)
     {
         //Logger.ErrorException(e.Message, e);
         throw e;
     }
 }
Exemple #5
0
        public async Task <Invoice> GetAllTransactions(string customerId)
        {
            try
            {
                var item        = (await _rep.Get()).Where(b => b.UserId.Equals(customerId));
                var inventories = await _inventoryProvider.GetAllInventories();

                var dtOs = Mapper.Map <IEnumerable <TransactionDTo> >(item).ToList();

                var result = from transaction in dtOs
                             join inventory in inventories on transaction.EquipmentId equals inventory.InventoryID
                             select new TransactionDTo
                {
                    Days   = transaction.Days,
                    Points = transaction.Points,
                    Price  = transaction.Price,
                    TransactionDateTime = transaction.TransactionDateTime,
                    Type          = inventory.Type,
                    EquipmentName = inventory.Name
                };

                //Since this is just for demonstration purposes and we have just a single user
                //in the system we have returned "Admin" as the customer's name (See the Invoice.CustomerName property)
                //However in a real production we can retrieve the Customer's name from User's table like below

                //var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                //var customer = await _appDbContext.Users.SingleOrDefaultAsync(c => c.Id == userId);

                var invoice = new Invoice
                {
                    Transactions = result,
                    TotalPoints  = dtOs.Sum(c => c.Points),
                    TotalPrice   = dtOs.Sum(c => c.Price)
                };
                return(invoice);
            }
            catch (Exception e)
            {
                _logger.LogInformation(e.Message);
                throw;
            }
        }
        public async Task <bool?> DeleteProperty(int id)
        {
            try
            {
                if (!_rep.Exists(id))
                {
                    return(false);
                }
                var entityToDelete = await _rep.Get(id);

                _rep.Delete(entityToDelete);
                if (!_rep.Save())
                {
                    return(null);
                }
                return(true);
            }
            catch (Exception e)
            {
                //Logger.ErrorException(e.Message, e);
                throw;
            }
        }
        public async Task <IEnumerable <StudentDto> > GetAllStudents()
        {
            try
            {
                var item = await _rep.Get();

                var dtOs = _mapper.Map <IEnumerable <StudentDto> >(item);
                return(dtOs);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemple #8
0
        public async Task <IEnumerable <InventoryDto> > GetAllInventories()
        {
            try
            {
                var items = await _rep.Get();

                return(items);
            }
            catch (Exception e)
            {
                //Logger.ErrorException(e.Message, e);
                throw e;
            }
        }
Exemple #9
0
        public async Task <IEnumerable <InventoryDto> > GetAllInventories()
        {
            try
            {
                var item = await _rep.Get();

                var dtOs = Mapper.Map <IEnumerable <InventoryDto> >(item);
                return(dtOs);
            }
            catch (Exception e)
            {
                _logger.LogInformation(e.Message);
                throw;
            }
        }
Exemple #10
0
        public async Task <ItemDto> Handle(GetItemQuery request, CancellationToken cancellationToken)
        {
            var entity = await _repository.Get(
                filter : source => source.Id == request.Id,
                include : source => source
                .Include(x => x.Ingredients)
                .ThenInclude(x => x.Ingredient)
                .Include(x => x.Allergens)
                .ThenInclude(x => x.Allergen)
                .Include(x => x.Category),
                cancellationToken : cancellationToken
                );

            if (entity == null)
            {
                throw new NotFoundException(nameof(Item), $"Could not find entity with id: {request.Id}");
            }
            return(entity);
        }