Beispiel #1
0
        public void ShouldDeleteACategoryEntityFromDbSet()
        {
            _repo.AddRange(new List <Category>
            {
                new Category {
                    CategoryName = "Foo"
                },
            });
            Assert.Equal(1, _repo.Table.Count());
            var category = _repo.GetAll().First();
            var count    = _repo.Delete(category);

            Assert.Equal(1, count);
            Assert.Equal(0, _repo.Table.Count());
        }
        public IActionResult Delete(int id)
        {
            var category = repo.GetCategory(id);

            repo.Delete(category);
            return(RedirectToAction("All"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Category category = categoryRepo.Get(id);

            categoryRepo.Delete(category);
            return(RedirectToAction("Index"));
        }
        public HttpResponseMessage Delete(DeleteDTO dto)
        {
            var cat = _repository.Get(dto.categoryId, ActiveModule.ModuleID);

            _repository.Delete(cat);

            return(Request.CreateResponse(System.Net.HttpStatusCode.NoContent));
        }
        public void ShouldNotDeleteOnConcurrencyIssue()
        {
            var category = new Category {
                CategoryName = "Foo"
            };

            _repo.Add(category);
            _repo.Context.Database.ExecuteSqlRaw("Update Store.Categories set CategoryName = 'Bar'");
            var ex = Assert.Throws <SpyStoreConcurrencyException>(() => _repo.Delete(category));
        }
        public IActionResult DeletePost(int?id)
        {
            Category category = categoryDAO.GetById(id);

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

            categoryDAO.Delete(category);
            return(RedirectToAction("Index"));
        }
 public IActionResult Delete(Guid id)
 {
     if (id != null)
     {
         _repo.Delete(id);
         if (_repo.SaveChanges() > 0)
         {
             return(Ok("deleted"));
         }
     }
     return(NotFound());
 }
Beispiel #8
0
        public ActionResult DeleteCategory(int id)
        {
            var categoryFromRepo = repository.GetById(x => x.Id == id);

            if (categoryFromRepo == null)
            {
                return(NotFound());
            }
            repository.Delete(categoryFromRepo.Result);
            repository.SaveChanges();
            return(NoContent());
        }
Beispiel #9
0
 public ActionResult Delete(int?categoryId)
 {
     try
     {
         Category category = _categoryRepo.GetById((int)categoryId);
         _categoryRepo.Delete(category);
         _categoryRepo.SaveChanges();
         return(RedirectToAction("ManageCategories", "Admin"));
     } catch (Exception e)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
 }
Beispiel #10
0
        public async Task <ActionResult> DeleteCategory(string id)
        {
            try
            {
                var categoryToDelete = await repo.GetById(id);

                if (categoryToDelete == null)
                {
                    return(NotFound($"Category with Id = {id} not found"));
                }
                var result = await repo.Delete(id);

                if (result)
                {
                    return(Ok());
                }
                return(BadRequest());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  $"Error Deleting data. Error message:{e.Message}"));
            }
        }
Beispiel #11
0
        public IActionResult Delete(int id)
        {
            _categoryRepos.Delete(id);

            return(RedirectToAction("Index"));
        }
Beispiel #12
0
        public IHttpActionResult Delete(int id)
        {
            var category = _categoryRepo.Delete(id);

            return(Ok(category));
        }