public async Task <ActionResult> Delete(int id) { var repository = new ItemsRepository(_context); Item item = await repository.GetById(id); if (item == null) { return(NotFound()); } try { repository.Delete(item); repository.Save(); return(NoContent()); } catch (Exception e) { return(BadRequest(new { message = e.Message.Replace('{', '(').Replace('}', ')') })); } }
public IHttpActionResult Delete(string label) { try { ICallContext callContext = GetCallContext(); var itemToDelete = ItemsRepository.GetByLabel(label); if (itemToDelete == null) { return(NotFound()); } itemToDelete = ItemsRepository.Delete(callContext, itemToDelete); if (itemToDelete == null) { return(BadRequest()); } return(Ok(ModelFactory.Create(itemToDelete))); } catch (Exception ex) { return(InternalServerError(ex)); } }
protected virtual void Delete() { RoleplayContext ctx = Singletons.RoleplayContextFactory.Create(); using (ItemsRepository repository = new ItemsRepository(ctx)) { repository.Delete(DbModel.Id); repository.Save(); } }
public string Delete(int id, string userId) { Item exists = _repo.Get(id); if (exists == null || exists.UserId != userId) { new Exception("Invalid Item ID"); } _repo.Delete(id, userId); return("Successfully Deleted Item"); }
public string Delete(string id) { Item item = _repo.Get(id); if (item == null) { throw new Exception("Invalid Id"); } _repo.Delete(id); return("Successfully deleted"); }
// internal Item Edit(Item updatedItem) // { // Item found = GetById(updatedItem.Id, updatedItem.UserId); // if (found.UserId != updatedItem.UserId) // { // throw new Exception("Invalid Request"); // } // found.Name = updatedItem.Name; // found.Description = updatedItem.Description; // found.ImgUrl = updatedItem.ImgUrl != null ? updatedItem.ImgUrl : found.ImgUrl; // return _repo.Edit(found); // } internal Item Delete(int id, string userId) { Item found = GetById(id, userId); if (found.UserId != userId) { throw new Exception("Invalid Request"); } if (_repo.Delete(id)) { return(found); } throw new Exception("Something went terribly wrong"); }
internal string Delete(int id, string userId) { var exists = GetById(id); if (exists == null) { throw new Exception("Invalid id"); } else if (userId != exists.UserId) { throw new Exception("You do not own this Keep peasant!"); } _repo.Delete(id); return("Successfully Destroyed"); }
public async Task <IActionResult> Delete(Guid?id) { if (id == null) { return(BadRequest()); } var item = await _itemsRepository.Find(id.Value); if (item == null) { return(NotFound()); } await _itemsRepository.Delete(item); return(NoContent()); }
public DeleteItemResponse Handle(DeleteItemRequest request) { var response = new DeleteItemResponse(); response.Errors = Validate(request); if (response.HasErrors) { return(response); } try { _itemsRepository.Delete(request.ItemId); return(response); } catch (Exception) { response.Errors.Add(new ErrorStatus("BAD_REQUEST")); return(response); } }
public IActionResult OnPost(int id) { mItem.Delete(id); return(RedirectToPage("/Items/ShowItems")); }
public async Task <IActionResult> Delete(Items item) { await itemsRepository.Delete(item); return(RedirectToAction("Index")); }
public bool Delete(int itemId) { return(_itemsRepository.Delete(itemId)); }