public async Task <IActionResult> GetInventories() { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var dtOs = await _provider.GetAllInventories(); return(Ok(dtOs)); }
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; } }