public ActionResult Delete(Category category)
        {
            //  var cat = categoriesService.GetCategory(category.ID);

            categoriesService.DeleteCategory(category.ID);
            return(RedirectToAction("Index"));
        }
        public async Task DeleteCategoryShouldReturnFalseForNotFoundId()
        {
            var categoriesRepo = new Mock <IRepository <Category> >();
            var categoryId     = Guid.NewGuid();
            var categories     = new List <Category>()
            {
                new Category {
                    Name = "Jackets", Id = categoryId
                },
                new Category {
                    Name = "Suits", Id = Guid.NewGuid()
                },
                new Category {
                    Name = "Something", Id = Guid.NewGuid()
                },
                new Category {
                    Name = "T-shirts", Id = Guid.NewGuid()
                }
            };

            categoriesRepo.Setup(r => r.All()).Returns(categories.AsQueryable());

            var service = new CategoriesService(categoriesRepo.Object);

            var result = await service.DeleteCategory(Guid.NewGuid().ToString());

            Assert.False(result);
            Assert.Equal(4, categories.Count);
            Assert.Contains(categories, c => c.Id == categoryId);
            Assert.Contains(categories, c => c.Name == "Jackets");
            categoriesRepo.Verify(r => r.Delete(It.IsAny <Category>()), Times.Never);
            categoriesRepo.Verify(r => r.SaveChangesAsync(), Times.Never);
        }
        public async Task DeleteCategoryShouldWork()
        {
            var categoriesRepo = new Mock <IRepository <Category> >();
            var categoryId     = Guid.NewGuid();
            var categories     = new List <Category>()
            {
                new Category {
                    Name = "Jackets", Id = categoryId
                },
                new Category {
                    Name = "Suits", Id = Guid.NewGuid()
                },
                new Category {
                    Name = "Something", Id = Guid.NewGuid()
                },
                new Category {
                    Name = "T-shirts", Id = Guid.NewGuid()
                }
            };

            categoriesRepo.Setup(r => r.All()).Returns(categories.AsQueryable());
            categoriesRepo.Setup(r => r.Delete(It.IsAny <Category>())).Callback <Category>(c => categories.Remove(c));

            var service = new CategoriesService(categoriesRepo.Object);

            var result = await service.DeleteCategory(categoryId.ToString());

            Assert.True(result);
            Assert.Equal(3, categories.Count);
            Assert.DoesNotContain(categories, c => c.Id == categoryId);
            Assert.DoesNotContain(categories, c => c.Name == "Jackets");
            categoriesRepo.Verify(r => r.Delete(It.IsAny <Category>()), Times.Once);
            categoriesRepo.Verify(r => r.SaveChangesAsync(), Times.Once);
        }
 public ActionResult Delete(Category category)
 {
     //category = categoryservice.GetCategory(category.ID);
     categoryservice.DeleteCategory(category.ID);
     //return View(category);
     return(RedirectToAction("Index"));
 }
Example #5
0
        public ActionResult Delete(Category category)
        {
            categoriesService.DeleteCategory(category.ID);
            //categoriesService.DeleteCategory(category);


            return(RedirectToAction("Index"));
        }
Example #6
0
 public ActionResult <string> Delete(string id)
 {
     try
     {
         return(Ok(_cs.DeleteCategory(id)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public async Task GivenCategoryName_ThenRepositoryDeleteCategoryCalledWithCorrectArguments()
        {
            const string categoryName = "category Name 123";
            var          service      = new CategoriesService(_mockCurrentUserContext.Object, _mockRepository.Object,
                                                              _mockMapper.Object);

            _mockRepository.Setup(repository => repository.DeleteCategory(It.IsAny <string>(), It.IsAny <string>()));

            await service.DeleteCategory(categoryName);

            _mockRepository.Verify(repository => repository.DeleteCategory(UserId, categoryName));
        }
 [HttpDelete("{id}")] //NOTE  not sure if this is needed
 public ActionResult <Category> Delete(string id)
 {
     try
     {
         var category = _cs.DeleteCategory(id);
         return(Ok(category));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Example #9
0
 public IActionResult Delete(int Id)
 {
     try
     {
         _categoriesService.DeleteCategory(Id);
         return(Ok());
     }
     catch
     {
         return(BadRequest());
     }
 }
Example #10
0
 public ActionResult Delete(Category category)
 {
     try
     {
         if (ModelState.IsValid)
         {
             categoyService.DeleteCategory(category.ID);
         }
     }
     catch (Exception ex)
     {
         return(HttpNotFound());
     }
     return(RedirectToAction("Index"));
 }
Example #11
0
        public IActionResult Delete(int id, HttpResponse response, HttpSession session)
        {
            if (!AuthenticationManager.IsAuthenticated(session))
            {
                this.Redirect(response, "/forum/login");
                return(null);
            }

            var user = AuthenticationManager.GetAuthenticatedUser(session.Id);

            if (user.IsAdmin == false)
            {
                this.Redirect(response, "/home/topics");
                return(null);
            }

            service.DeleteCategory(id);
            this.Redirect(response, "/categories/all");
            return(null);
        }
Example #12
0
        public ActionResult Delete(int ID)
        {
            categoriesService.DeleteCategory(ID);

            return(RedirectToAction("CategoryTabble"));
        }
        public ActionResult Delete(Category category)
        {
            categoriesService.DeleteCategory(category);

            return(RedirectToAction("Listing"));
        }
 public ActionResult Delete(Category category)
 {
     category = cateserv.GetCategory(category.ID);
     cateserv.DeleteCategory(category);
     return(RedirectToAction("Index"));
 }
 public IActionResult DeleteCategory(int categoryId)
 {
     _categoriesService.DeleteCategory(categoryId);
     return(NoContent());
 }