public void Delete() { int validator = 0; Tag tag = new Tag(); string result = null; string tagName = null; while (validate.ValidateTagName(tagName) != 0) { Console.Write("\nName: "); tagName = Console.ReadLine().Trim().ToLower(); validator = validate.ValidateTagName(tagName); if (validator == 0) { result = "Successfully deleted tag!"; break; } else if (validator == -1) { result = "Name cannot be empty!"; } else if (validator == 1) { result = "Such tag doesn't exist!"; } Console.WriteLine(result); } tag.Name = tagName; context.Remove(context.Tags.First(x => x.Name == tag.Name)); context.SaveChanges(); Console.WriteLine(result); }
public void Delete() { int validator = 0; Movie movie = new Movie(); string result = null; string movieName = null; while (validate.ValidateMovieName(movieName) != 0) { Console.Write("\nName: "); movieName = Console.ReadLine().Trim().ToLower(); if (validate.ValidateMovieName(movieName) != -1) { movieName = movieName.First().ToString().ToUpper() + movieName.Substring(1); } validator = validate.ValidateMovieName(movieName); if (validator == 0) { result = "Successfully deleted movie!"; break; } else if (validator == -1) { result = "Name cannot be empty!"; } else if (validator == 1) { result = "Such movie doesn't exist!"; } Console.WriteLine(result); } movie.Name = movieName; context.RemoveRange(context.Ratings.First(x => x.Movie.Name == movie.Name)); context.Remove(context.Movies.First(x => x.Name == movie.Name)); context.SaveChanges(); Console.WriteLine(result); }
public async Task <ActionResult> Delete(int id) { try { var exist = await _db.Genres.AnyAsync(x => x.Id == id); if (!exist) { return(NotFound()); } _db.Remove(new Genre() { Id = id }); await _db.SaveChangesAsync(); return(NoContent()); } catch (Exception ex) { return(BadRequest(ex)); } }