Ejemplo n.º 1
0
        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));
            }
        }
Ejemplo n.º 3
0
        protected virtual void Delete()
        {
            RoleplayContext ctx = Singletons.RoleplayContextFactory.Create();

            using (ItemsRepository repository = new ItemsRepository(ctx))
            {
                repository.Delete(DbModel.Id);
                repository.Save();
            }
        }
Ejemplo n.º 4
0
        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");
        }
Ejemplo n.º 5
0
        public string Delete(string id)
        {
            Item item = _repo.Get(id);

            if (item == null)
            {
                throw new Exception("Invalid Id");
            }
            _repo.Delete(id);
            return("Successfully deleted");
        }
Ejemplo n.º 6
0
        //  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");
        }
Ejemplo n.º 8
0
        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());
        }
Ejemplo n.º 9
0
        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);
            }
        }
Ejemplo n.º 10
0
 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"));
        }
Ejemplo n.º 12
0
 public bool Delete(int itemId)
 {
     return(_itemsRepository.Delete(itemId));
 }