private void UploadImage(ProductDocDb product) { byte[] byteArray = Convert.FromBase64String(product.ImageUrls); string name = product.Title + ".jpg"; using MemoryStream stream = new MemoryStream(byteArray, writable: false); blobStorage.UploadFileToStorage(BlobContainers.products, name, stream); }
private async Task <decimal> GetTotalPrice(IEnumerable <CartLine> lines) { IEnumerable <ProductDocDb> allMainProducts = await productRepository.MainProducts().ConfigureAwait(false); decimal totalPrice = 0; foreach (CartLine cartLine in lines) { string optionValuesPricePair = string.Join(string.Empty, cartLine.selectedOptionsArray); ProductDocDb product = allMainProducts.Where(p => p.Id == cartLine.productId).FirstOrDefault(); int price = int.Parse(product.OptionValuesPricePairs[optionValuesPricePair][0]); totalPrice += price; } return(totalPrice); }
public IActionResult ReplaceProduct(string id, [FromBody] ProductDocDb pdata) { if (ModelState.IsValid) { //Guid.TryParse(id, out Guid productId); pdata.Id = id; UploadImage(pdata); repository.SaveProduct(pdata, newProduct: false); return(Ok()); } else { return(BadRequest(ModelState)); } }
public async Task <IActionResult> UpdateProduct(string id, [FromBody] JsonPatchDocument <ProductDocDb> patch) { IQueryable <ProductDocDb> products = await repository.MainProducts().ConfigureAwait(false); ProductDocDb product = products.First(p => p.Id == id); if (ModelState.IsValid && TryValidateModel(product)) { UploadImage(product); await repository.SaveProduct(product, newProduct : false).ConfigureAwait(false); return(Ok()); } else { return(BadRequest(ModelState)); } }
public IActionResult CreateProduct([FromBody] Product pdata) { if (ModelState.IsValid) { ProductDocDb docDbProduct = new ProductDocDb { Title = pdata.Title, Description = pdata.Description, Price = pdata.Price, Categories = pdata.Categories, ImageUrls = pdata.ImageUrls }; UploadImage(docDbProduct); repository.SaveProduct(docDbProduct); return(Ok(docDbProduct.Id)); } else { return(BadRequest(ModelState)); } }
private async Task <decimal> GetTotalPrice(IEnumerable <CartLine> lines) { //IEnumerable<string> ids = lines.Select(l => l.productId); //IEnumerable<ProductDocDb> prods = allMainProducts.Where(p => ids.Contains(p.Id)); IEnumerable <ProductDocDb> allMainProducts = await productrepository.MainProducts().ConfigureAwait(false); decimal totalPrice = 0; foreach (CartLine cartLine in lines) { string optionValuesPricePair = string.Join(string.Empty, cartLine.selectedOptionsArray); ProductDocDb product = allMainProducts.Where(p => p.Id == cartLine.productId).FirstOrDefault(); int price = int.Parse(product.OptionValuesPricePairs[optionValuesPricePair][0]); totalPrice += price; } return(totalPrice); //return prods.Select(p => lines // .First(l => l.productId == p.Id).quantity * p.OptionValuesPricePairs[lines.] * Price) // .Sum(); }
public async Task <IActionResult> GetProduct(string id) { ProductDocDb product = await repository.GetProduct(id).ConfigureAwait(false); return(Ok(product)); }