Пример #1
0
        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));
        }
Пример #2
0
        public void GetProduct_ShouldSucceed(int id)
        {
            ProductsLogic logic  = new ProductsLogic(new MockUnitOfWork());
            var           result = logic.GetProduct(id);

            Assert.Equal(result.Id, id);
        }
Пример #3
0
 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"
         }));
     }
 }
Пример #4
0
        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;
        }
Пример #5
0
        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));
        }
Пример #6
0
        public void GetProduct_ShouldThrowNotFoundException(int id)
        {
            ProductsLogic logic = new ProductsLogic(new MockUnitOfWork());

            Assert.Throws <NotFoundException>(() => logic.GetProduct(id));
        }