public IHttpActionResult DeleteProduct(string token, int userId, int id) { if (!ApplicationHelper.IsTokenValid(token, userId)) { return(Content(HttpStatusCode.BadRequest, "BadRequest")); } var product = ProductsLogic.GetProduct(id); if (product == null) { return(Content(HttpStatusCode.NotFound, "NotFound")); } var result = ProductsLogic.DeleteProduct(id); if (!result.Success) { ApplicationHelper.Log(result.Message); } return(result.Success ? Content(HttpStatusCode.OK, "OK") : Content(HttpStatusCode.InternalServerError, result.Message)); }
public void GetProduct_ShouldSucceed(int id) { ProductsLogic logic = new ProductsLogic(new MockUnitOfWork()); var result = logic.GetProduct(id); Assert.Equal(result.Id, id); }
public IActionResult GetProduct(int id) { try { var result = _logic.GetProduct(id).ConvertProductToVM(); return(Ok(result)); } 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" })); } }
private void GetProduct(int id) { ProductsLogic pl = new ProductsLogic(); Products p = pl.GetProduct(id); ProductPanel.Visible = true; idProductTextBox.Text = p.ProductID.ToString(); productNameTextBox.Text = p.ProductName; }
public IHttpActionResult GetProduct(string token, int userId, int id) { if (!ApplicationHelper.IsTokenValid(token, userId)) { return(Content(HttpStatusCode.BadRequest, "BadRequest")); } var product = ProductsLogic.GetProduct(id); if (product == null) { return(Content(HttpStatusCode.NotFound, "NotFound")); } return(Content(HttpStatusCode.OK, product)); }
public void GetProduct_ShouldThrowNotFoundException(int id) { ProductsLogic logic = new ProductsLogic(new MockUnitOfWork()); Assert.Throws <NotFoundException>(() => logic.GetProduct(id)); }