Example #1
0
        public async Task <ActionResult <InventoryItemDTOListResult> > GetInventoryItemsWithOptionByName(string name)
        {
            InventoryItemDTOListResult result = new InventoryItemDTOListResult();

            try
            {
                if (string.IsNullOrEmpty(name))
                {
                    _logger.LogInformation($"InventoryService::GetInventoryItemsWithOptionByName. Error: Inventory item option name must be provided.");
                    return(new BadRequestObjectResult(new { statuscode = 400, message = "Option name must be provided" }));
                }
                else
                {
                    var items = await _context.InventoryItem.Include(i => i.InventoryItemOptions).Where(p => p.InventoryItemOptions.Any(o => o.Name.ToLower() == name.ToLower())).ToListAsync();

                    if (items == null)
                    {
                        return(new BadRequestObjectResult(new { statuscode = 400, message = $"No inventory items with option name {name} found." }));
                    }

                    result.Items = items.Select(i => InventoryItemToDTO(i)).ToList();
                    _logger.LogInformation($"InventoryService::GetInventoryItemsWithOptionByName. Found {result.Items.Count()} Inventory items with option name {name}.");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"InventoryService::GetInventoryItemsWithOptionByName. Exception: {ex.Message}", ex);
            }

            return(new OkObjectResult(result.Items));
        }
Example #2
0
        public async Task <ActionResult <InventoryItemDTOListResult> > GetInventoryItems(string name = "")
        {
            InventoryItemDTOListResult result = new InventoryItemDTOListResult();

            try
            {
                if (string.IsNullOrEmpty(name))
                {
                    result.Items = await _context.InventoryItem.Select(p => InventoryItemToDTO(p)).ToListAsync();

                    _logger.LogInformation($"InventoryService::GetInventory. Found {result.Items.Count()} inventory items.");
                }
                else
                {
                    result.Items = await _context.InventoryItem.Where(p => p.Name.ToLower().Contains(name.ToLower())).Select(p => InventoryItemToDTO(p)).ToListAsync();

                    _logger.LogInformation($"InventoryService::GetInventory. Found {result.Items.Count()} Inventory with name {name}.");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"InventoryService::GetInventory. Exception: {ex.Message}", ex);
            }

            return(new OkObjectResult(result.Items));
        }
Example #3
0
        public async Task <ActionResult <InventoryItemDTOListResult> > GetTop3InventoryItems()
        {
            InventoryItemDTOListResult result = new InventoryItemDTOListResult();

            try
            {
                result.Items = await _context.InventoryItem.OrderByDescending(p => p.Price).Take(3).Select(p => InventoryItemToDTO(p)).ToListAsync();

                _logger.LogInformation($"InventoryService::GetTop3InventoryItems. Successfully found top 3 inventory items.");
            }
            catch (Exception ex)
            {
                _logger.LogError($"InventoryService::GetTop3InventoryItems. Exception: {ex.Message}", ex);
            }

            return(new OkObjectResult(result.Items));
        }