예제 #1
0
        public void DeleteDoesntRemoveNewProduct()
        {
            _repo.Setup(r => r.Get(_id1)).Returns <IProduct>(null);

            _service.Delete(_id1);

            _repo.Verify(r => r.Get(_id1), Times.Once);
            _repo.Verify(r => r.Remove(_id1), Times.Never);
        }
예제 #2
0
        public void Delete_Should_Delete_Product()
        {
            string errorMessagePrefix = "ProductsService Delete() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.productsService = new ProductsService(context);

            var product = new Product
            {
                Id              = "Id1",
                Name            = "Product1",
                ProductCode     = "01010101",
                Viscosity       = "10/10",
                PackageCapacity = 180,
                isDeleted       = false,
            };

            context.Products.Add(product);
            context.SaveChanges();

            var result = productsService.Delete("Id1");

            Assert.True(result.isDeleted);
        }
        public async Task <IActionResult> DeleteProduct(int productId)
        {
            var product = await _servicePro.Find(productId);

            _servicePro.Delete(product);

            return(Ok("Silindi"));
        }
        public ActionResult Delete(int id)
        {
            var model = service.GetById(id);

            service.Delete(model);

            return(new AjaxResult().NotifyMessage("DELETE_ENTITY_COMPLETE").Alert(T("Đã xóa thành công.")));
        }
예제 #5
0
        public IActionResult Delete(DeleteProductViewModel model)
        {
            var mappedProductFromModel = this.mapper.Map <Product>(model);

            productsService.Delete(mappedProductFromModel);
            productsService.Save();
            return(this.RedirectToAction("Index", "Products"));
        }
예제 #6
0
 public IActionResult Delete([FromRoute] string id)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _service.Delete(id);
     return(NoContent());
 }
예제 #7
0
        public ActionResult <ProductDto> Delete(string id)
        {
            var result = _productsService.Delete(id);

            if (result == null)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
예제 #8
0
        public async Task <IActionResult> Delete(Guid id)
        {
            if (!User.IsInRole("Admin"))
            {
                return(BadRequest("Not Authorized"));
            }
            await _productsService.Delete(id);

            return(Ok());
        }
예제 #9
0
        public ActionResult Delete(string id)
        {
            var product = _productsService.Delete(id);

            if (product == null)
            {
                return(NotFound());
            }

            return(NoContent());
        }
        public ActionResult <string> Delete(string id)
        {
            string result = _productsService.Delete(id);

            if (result != null)
            {
                return(Ok(result));
            }

            return(NotFound("Product not found"));
        }
        public ActionResult <ProductDto> Delete(string id)
        {
            var isDeleted = _productsService.Delete(id);

            if (!isDeleted)
            {
                return(NotFound());
            }

            return(Ok());
        }
 public ActionResult Delete(string id)
 {
     try
     {
         var deletedProduct = _productsService.Delete(id);
         return(Ok());
     }
     catch (System.Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
        public ActionResult <ProductDto> Delete(Guid id)
        {
            try
            {
                _productsService.Delete(id);
            }
            catch (NotFoundException)
            {
                NotFound();
            }

            return(NoContent());
        }
예제 #14
0
 public int Delete(int ProductID)
 {
     try
     {
         int res = _ProductsService.Delete(ProductID);
         return(res);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         throw ex;
     }
 }
예제 #15
0
 public ActionResult Delete(int id)
 {
     try
     {
         _productsService.Delete(_ => _.Id == id);
         _productsService.SaveChanges();
         return(StatusCode(204));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public IActionResult DeleteFilm(string id)
        {
            Film film = _filmService.GetById(id);

            if (film == null)
            {
                return(NotFound());
            }

            _filmService.Delete(id);

            return(Ok());
        }
예제 #17
0
        public IActionResult DeleteBook(string id)
        {
            Book book = _bookService.GetById(id);

            if (book == null)
            {
                return(NotFound());
            }

            _bookService.Delete(id);

            return(Ok());
        }
        public ActionResult Delete(Guid id)
        {
            var deleted = _productsService.Delete(id.ToString());

            if (deleted != null)
            {
                return(Ok());
            }
            else
            {
                return(NotFound());
            }
        }
예제 #19
0
        public ActionResult Delete(string id)
        {
            ProductDto deletedProduct = _productsService.Delete(id);

            if (deletedProduct == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok("The product with id:" + id + "was deleted succesfully!"));
            }
        }
        public IActionResult DeleteGame(string id)
        {
            Game game = _gameService.GetById(id);

            if (game == null)
            {
                return(NotFound());
            }

            _gameService.Delete(id);

            return(Ok());
        }
예제 #21
0
        public async Task <IActionResult> Delete(Guid id)
        {
            var success = await _productsService.Delete(id);

            if (success)
            {
                return(Ok(success));
            }
            else
            {
                return(BadRequest(success));
            }
        }
예제 #22
0
        public async Task <ActionResult> Delete(string id)
        {
            var result = await _productsService.Delete(id);

            if (result)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest("The product specified does not exist!"));
            }
        }
예제 #23
0
        public IActionResult Delete(string id)
        {
            try
            {
                _productsService.Delete(id);

                return(NoContent());
            }
            catch (ProductException ex)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, ex.Message));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Something unexpected occurred. Please contact the system administration."));
            }
        }
        public async Task <IActionResult> Delete(int code)
        {
            try
            {
                var response = await _service.Delete(code);

                if (response == false)
                {
                    return(NotFound("Produto não encontrado"));
                }

                return(Ok("Produto Deletado"));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
예제 #25
0
        public IActionResult Delete([FromQuery] int id)
        {
            ResultCode resultCode; int?productID;

            (resultCode, productID) = _service.Delete(id);

            Result error; int statusCode;

            (statusCode, error) = ResultHandler.GetStatusCodeAndResult(resultCode);

            GeneralResponse response = new GeneralResponse
            {
                Result = productID,
                Error  = error,
            };

            return(StatusCode(statusCode, response));
        }
예제 #26
0
        public IActionResult DeleteConfirmed(Guid id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Product product = productsService.GetById(id);

            if (product == null)
            {
                return(NotFound());
            }

            product.DeletedOn = DateTime.Now;

            productsService.Delete(product);

            return(RedirectToAction("Index"));
        }
예제 #27
0
 public ActionResult Delete(int id, [FromHeader] string Token, [FromHeader] int Access)
 {
     try
     {
         if (_authService.Authorization(Token) == true)
         {
             bool response = _productService.Delete(id, _authService.IsAdmin(Access));
             return(Ok(response));
         }
         else
         {
             throw new Exception("Sem Permissão para acessas.");
         }
     }
     catch (Exception ex)
     {
         Response.StatusCode = 403;
         return(BadRequest(StatusCode(403, ex.Message)));
     }
 }
예제 #28
0
 public ActionResult Delete(int id)
 {
     if (id <= 0)
     {
         throw new HttpRequestValidationException();
     }
     try
     {
         Products model = _proSvc.Getbykey(id);
         _proSvc.Delete(model);
         _proSvc.CommitChanges();
         log.Info("Delete Products by: " + HttpContext.User.Identity.Name);
         Messages.AddFlashMessage(Resources.Message.Prod_DMesSuccess);
     }
     catch (Exception ex)
     {
         log.Error(" Delete -" + ex);
         Messages.AddErrorFlashMessage(Resources.Message.Prod_DMesUnsuccess);
     }
     return(RedirectToAction("Index"));
 }
예제 #29
0
        public async Task <IActionResult> Delete(long?id, string slug)
        {
            Product product;

            if (id != null)
            {
                product = await _productsService.FetchById(id.Value);
            }
            else
            {
                product = await _productsService.FetchBySlug(slug);
            }

            if (product == null)
            {
                return(StatusCodeAndDtoWrapper.BuildGenericNotFound());
            }

            var result = await _authorizationService.AuthorizeAsync(User, product,
                                                                    _configurationService.GetManageProductPolicyName());

            if (result.Succeeded)
            {
                if ((await _productsService.Delete(product)) > 0)
                {
                    return(StatusCodeAndDtoWrapper.BuildSuccess("Product deleted successfully"));
                }
                else
                {
                    return(StatusCodeAndDtoWrapper.BuildErrorResponse("An error occured, try later"));
                }
            }
            else
            {
                return(StatusCodeAndDtoWrapper.BuildUnauthorized("Access denied"));
            }
        }
 public ActionResult Delete(string id)
 {
     _productsService.Delete(id);
     return(Ok());
 }