public async Task <ServiceResponse <List <GetCartPricesDto> > > BestStore(SendShoppingCartDto cart) { ServiceResponse <List <GetCartPricesDto> > serviceResponse = new ServiceResponse <List <GetCartPricesDto> >(); List <GetCartPricesDto> a = new List <GetCartPricesDto>(); try { foreach (var itemID in cart.Cart) { var info = await(from price in _context.ItemPrices join rec in _context.Receipts on price.ReceiptId equals rec.Id select new GetCartPricesDto { Id = price.ItemId, Price = price.Price, Date = rec.Date, Shop = rec.Shop }).OrderByDescending(x => x.Date).FirstOrDefaultAsync(x => x.Id == itemID); a.Add(info); } serviceResponse.Data = a; return(serviceResponse); } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = ex.Message; } return(serviceResponse); }
public async Task <ServiceResponse <List <GetItemDto> > > GetItemList(SendShoppingCartDto cart) { ServiceResponse <List <GetItemDto> > serviceResponse = new ServiceResponse <List <GetItemDto> >(); List <GetItemDto> items = new List <GetItemDto>(); try { foreach (var itemId in cart.Cart) { var item = await _context.Items.FirstOrDefaultAsync(a => a.Id == itemId); items.Add(_mapper.Map <GetItemDto>(item)); } serviceResponse.Data = items; return(serviceResponse); } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = ex.Message; } return(serviceResponse); }
public async Task <ServiceResponse <List <GetCartPricesDto> > > BestStoreCustom(Shop[] filter, SendShoppingCartDto cart) { ServiceResponse <List <GetCartPricesDto> > serviceResponse = new ServiceResponse <List <GetCartPricesDto> >(); List <GetCartPricesDto> a = new List <GetCartPricesDto>(); try { foreach (var itemID in cart.Cart) { var list = await _context.ItemPrices.Include(x => x.Receipt).Where(x => x.ReceiptId == x.Receipt.Id).Select(x => new GetCartPricesDto { Id = x.ItemId, Price = x.Price, Shop = x.Receipt.Shop, Date = x.Receipt.Date.Date }).ToListAsync(); List <GetCartPricesDto> prices = new List <GetCartPricesDto>(); foreach (var shop in filter) { var info = list.OrderByDescending(x => x.Date).FirstOrDefault(x => x.Id == itemID && x.Shop == shop); if (info != null) { prices.Add(info); } } if (prices != null) { var b = prices.OrderBy(x => x.Price).FirstOrDefault(); a.Add(b); } } if (a != null) { serviceResponse.Data = a; } else { serviceResponse.Message = "Did not find any item prices"; serviceResponse.Success = false; } return(serviceResponse); } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = ex.Message; } return(serviceResponse); }
public async Task <IActionResult> BestStore([FromQuery(Name = "shops")] Shop[] shop, [FromBody] SendShoppingCartDto cart) { return(Ok(await _ShoppingCartService.BestStoreCustom(shop, cart))); }
public async Task <IActionResult> BestStore(SendShoppingCartDto cart) { return(Ok(await _ShoppingCartService.BestStore(cart))); }
public async Task <IActionResult> ViewShoppingCart(SendShoppingCartDto cart) { return(Ok(await _ShoppingCartService.GetItemList(cart))); }