コード例 #1
0
        public async Task TestGet()
        {
            var products1 = await _pManager.GetAllProducts();

            var product = await _pManager.GetProduct(products1[0].ProductId);

            Assert.IsNotNull(product);
        }
コード例 #2
0
        public async Task <IHttpActionResult> GetProduct(Guid id)
        {
            //Product product = await db.Products.FindAsync(id);
            Product product;

            try
            {
                product = await _productManager.GetProduct(id);

                if (product != null && !string.IsNullOrEmpty(product.ImageAddress))
                {
                    try
                    {
                        product.Base64Image    = Convert.ToBase64String(System.IO.File.ReadAllBytes(product.ImageAddress));
                        product.Base64Thumbnil = Convert.ToBase64String(System.IO.File.ReadAllBytes(product.ImageAddress.Replace("UserImages", "UserThumbnils")));
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            catch (SqlException e)
            {
                return(BadRequest(e.GetBaseException().Message));
            }
            catch (CustomException.NotFoundException <Product> e)
            {
                return(NotFound());
            }
            catch (Exception e)
            {
                throw new CustomException.GeneralErrorMessage(e.GetBaseException().Message);
            }

            if (product == null)
            {
                return(NotFound());
            }

            return(Ok(product));
        }