示例#1
0
        public void CreateProduct_ShouldThrowBadRequestException(string title, string descirption,
                                                                 string imageURL, double price, int[] dts, string vendorUID)
        {
            ProductsLogic logic = new ProductsLogic(new MockUnitOfWork());

            Assert.Throws <BadRequestException>(() => logic.CreateProduct(title, descirption, imageURL, price, dts, vendorUID));
        }
示例#2
0
 public IActionResult CreateProduct(ProductCreationVM product)
 {
     try
     {
         _logic.CreateProduct(product.Title, product.Description, product.ImageURL, product.Price, product.DietaryTypeIds, product.VendorUID);
         return(Ok());
     }
     catch (BadRequestException e)
     {
         return(BadRequest(new HttpErrorResponse()
         {
             Message = e.Message,
             Subject = e.Subject
         }));
     }
     catch (NotFoundException e)
     {
         return(NotFound(new HttpErrorResponse()
         {
             Message = e.Message,
             Subject = e.Subject
         }));
     }
     catch (Exception e)
     {
         //Log Error
         return(StatusCode(500, new HttpErrorResponse()
         {
             Message = "Internal Error Occurred",
             Subject = "Internal"
         }));
     }
 }
示例#3
0
        public void CreateProduct_ShouldSucceed(string title, string descirption,
                                                string imageURL, double price, int[] dts, string vendorUID)
        {
            ProductsLogic logic = new ProductsLogic(new MockUnitOfWork());

            logic.CreateProduct(title, descirption, imageURL, price, dts, vendorUID);
            Assert.True(true);
        }
示例#4
0
        public IHttpActionResult CreateProduct(string token, int userId, Product product)
        {
            if (!ModelState.IsValid || !ApplicationHelper.IsTokenValid(token, userId))
            {
                return(Content(HttpStatusCode.BadRequest, "BadRequest"));
            }

            var result = ProductsLogic.CreateProduct(product);

            if (!result.Success)
            {
                ApplicationHelper.Log(result.Message);
            }

            return(result.Success
                ? Content(HttpStatusCode.OK, "OK")
                : Content(HttpStatusCode.InternalServerError, result.Message));
        }