Exemplo n.º 1
0
 public IHttpActionResult Delete(int?id)
 {
     try
     {
         if (id == null || id <= 0)
         {
             return(BadRequest());
         }
         var director = directorService.GetByID((int)id);
         if (director != null)
         {
             directorService.Delete(director);
             directorService.Save();
             return(StatusCode(HttpStatusCode.NoContent));
         }
         else
         {
             return(NotFound());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Exemplo n.º 2
0
        //[HandleError] // Devreye almak için web.config'te system.web altına eğer yoksa <customErrors mode="On"></customErrors> eklenmelidir.
        // Hata olması durumunda default olarak bu controller'a ait veya Shared klasöründeki Error.cshtml view'ını return eder.
        public ActionResult DeleteConfirmed(int id)
        {
            //Director director = db.Directors.Find(id);
            //db.Directors.Remove(director);
            //db.SaveChanges();
            directorService.Delete(id);

            return(RedirectToAction("Index"));
        }
        public IActionResult Delete([FromRoute] int id)
        {
            if (directorService.Delete(id))
            {
                return(NoContent());
            }

            return(BadRequest());
        }
Exemplo n.º 4
0
        public void DELETE_ShouldReturnOneDirectorLess()
        {
            //Arrange
            int x       = 2;
            var options = new DbContextOptionsBuilder <CinemaDbContext>()
                          .UseInMemoryDatabase(databaseName: "DELETE_ShouldReturnOneDirectorLess")
                          .Options;


            var context = new CinemaDbContext(options);

            SeedDirectors(context);

            var service = new DirectorService(context);


            //Act
            var result = service.Delete(x);


            //Assert
            Assert.True(result);
        }
        public string Delete(int directorId)
        {
            bool isDeleted = directorService.Delete(directorId);

            return(isDeleted ? "Director deleted successfully." : "Failed to delete the director.");
        }