public void UpdateProduct_ShouldThrowNotFoundException(int id, string title, string descirption, string imageURL, double price, int[] dts, string vendorUID) { ProductsLogic logic = new ProductsLogic(new MockUnitOfWork()); Assert.Throws <NotFoundException>(() => logic.UpdateProduct(id, title, descirption, imageURL, price, dts, vendorUID)); }
public IHttpActionResult UpdateProduct(string token, int userId, Product product) { if (!ModelState.IsValid || !ApplicationHelper.IsTokenValid(token, userId)) { return(Content(HttpStatusCode.BadRequest, "BadRequest")); } var productDb = ProductsLogic.GetProduct(product.productId); if (productDb == null) { return(Content(HttpStatusCode.NotFound, "NotFound")); } var result = ProductsLogic.UpdateProduct(product); if (!result.Success) { ApplicationHelper.Log(result.Message); } return(result.Success ? Content(HttpStatusCode.OK, "OK") : Content(HttpStatusCode.InternalServerError, result.Message)); }
public IActionResult UpdateProduct(int id, [FromBody] ProductCreationVM product) { try { _logic.UpdateProduct(id, 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" })); } }