Пример #1
0
 public async Task <ActionResult <ShoppingItemDTO> > Delete(Guid id)
 {
     try
     {
         return(ShoppingItemDTO.FromDbModel(await productsService.RemoveProductAsync(id)));
     }
     catch (Exception e)
     {
         return(Problem(e.Message, statusCode: StatusCodes.Status500InternalServerError));
     }
 }
Пример #2
0
 public ActionResult <IEnumerable <ShoppingItemDTO> > Get()
 {
     try
     {
         var items = productsService.GetAll().Select(i => ShoppingItemDTO.FromDbModel(i));
         return(Ok(items));
     }
     catch (Exception e)
     {
         logger.LogError(e, "Issue getting items!");
         return(Problem(e.Message, statusCode: StatusCodes.Status500InternalServerError));
     }
 }
Пример #3
0
 public async Task <ActionResult <ShoppingItemDTO> > Put(Guid id, [FromForm] ShoppingItem shoppingItem)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         return(ShoppingItemDTO.FromDbModel(await productsService.UpdateProductAsync(id, shoppingItem)));
     }
     catch (Exception e)
     {
         return(Problem(e.Message, statusCode: StatusCodes.Status500InternalServerError));
     }
 }
Пример #4
0
        public async Task <ActionResult <ShoppingItemDTO> > Get(Guid id)
        {
            try
            {
                IShoppingItem item = await productsService.GetItemByIDAsync(id);

                return(Ok(ShoppingItemDTO.FromDbModel(item)));
            }
            catch (KeyNotFoundException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                return(Problem(e.Message, statusCode: StatusCodes.Status500InternalServerError));
            }
        }
Пример #5
0
 public async Task <ActionResult <ShoppingItemDTO> > Post([FromForm] ShoppingItem shoppingItem)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         return(ShoppingItemDTO.FromDbModel(await productsService.AddProductAsync(shoppingItem)));
     }
     catch (ItemCreatedWithoutImageException e)
     {
         return(BadRequest(e.Message));
     }
     catch (Exception e)
     {
         return(Problem(e.Message, statusCode: StatusCodes.Status500InternalServerError));
     }
 }