public bool Delete(int id) { var actor = _repository.FindById(id); _repository.Delete(actor); return(_repository.SaveChanges()); }
public async Task <IActionResult> DeleteActor(int id) { try { if (id < 1) { return(BadRequest()); } var exists = await _actorRepo.Exists(id); if (!exists) { return(NotFound()); } var actor = await _actorRepo.FindById(id); var success = await _actorRepo.Delete(actor); if (!success) { ModelState.AddModelError("", "Something went wrong when Deleting the record"); return(StatusCode(500, ModelState)); } return(NoContent()); } catch (Exception e) { return(StatusCode(500, "Something went wrong. Please contact your admin")); } }
void Delete_Clicked(object sender, EventArgs e) { var mi = ((MenuItem)sender); var actor = mi.CommandParameter as Actor; actorRepository.Delete(actor); listview.ItemsSource = actorRepository.GetAll(); }
public void DeleteActor(int id) { var actor = actorRepository.GetById(id); if (actor != null) { castRepository.DeleteRange(c => c.ActorId == id); actorRepository.Delete(actor); } }
public bool Delete(string actorId) { var actor = _actorRepository.FindById(actorId); if (actor != null) { _actorRepository.Delete(actor); return(true); } return(false); }
public async Task Delete_RemovesActor() { var id = 1; Mock.Arrange(() => repo.Delete(id)) .Returns(() => Task.FromResult(true)) .MustBeCalled(); await target.Delete(id); Mock.Assert(repo); }
private async Task ExecuteQuery(Request request) { var descriptive = request.Descriptive.Split("#"); if (descriptive.Length != 2) { return; } if (descriptive[1] == "actor") { var entity = JsonConvert.DeserializeObject <Actor>(request.Payload); switch (descriptive[0]) { case "insert": await actorRepository.Insert(entity, new CancellationTokenSource().Token, false); break; case "update": await actorRepository.Update(entity, new CancellationTokenSource().Token, false); break; case "delete": await actorRepository.Delete(entity.Id, new CancellationTokenSource().Token, false); break; } } else if (descriptive[1] == "movie") { var entity = JsonConvert.DeserializeObject <Movie>(request.Payload); switch (descriptive[0]) { case "insert": await movieRepository.Insert(entity, new CancellationTokenSource().Token, false); break; case "update": await movieRepository.Update(entity, new CancellationTokenSource().Token, false); break; case "delete": await movieRepository.Delete(entity.Id, new CancellationTokenSource().Token, false); break; } } }
public async Task <IActionResult> DeleteActor([FromRoute] int id) { var deleteActor = _actorRepository.GetSingle(m => m.ID == id); if (deleteActor == null) { return(new NotFoundResult()); } else { _actorRepository.Delete(deleteActor); await _actorRepository.CommitAsync(); return(new NoContentResult()); } }
public async Task <IActionResult> DeleteActorById(int id) { try { var actor = await _repository.Get <Actor>(id); if (actor == null) { return(NotFound($"Could not delete actor. Actor with Id {id} was not found.")); } await _repository.Delete <Actor>(id); return(NoContent()); } catch (Exception e) { var result = new { Status = StatusCodes.Status500InternalServerError, Data = $"Failed to delete the actor. Exception thrown when attempting to delete data from the database: {e.Message}" }; return(this.StatusCode(StatusCodes.Status500InternalServerError, result)); } }
public async Task <ActionResult> DeleteActor(int actorId) { try { var oldActor = await _actorRepository.GetActorsById(actorId); if (oldActor == null) { return(NotFound($"Could not find actor with id {actorId}")); } _actorRepository.Delete(oldActor); if (await _actorRepository.Save()) { return(NoContent()); } } catch (Exception e) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e.Message}")); } return(BadRequest()); }
public async Task DeleteAndSave(int id) { _actorRepo.Delete(id); await _actorRepo.Save(); }
// GET: Actor/Delete/5 public async Task <ActionResult> Delete(int id) { await repository.Delete(id); return(RedirectToAction(nameof(Index))); }
public async Task <HttpStatusCodeResult> Delete(int id) { await repository.Delete(id); return(new NoContentResult()); }