예제 #1
0
    public HttpResponseMessage Delete(int shoppingListId, int shoppingListEntry)
    {
        var model = new DeleteShoppingListEntryInput
        {
            ShoppingListId      = shoppingListId,
            ShoppingListEntryId = shoppingListEntry,
            InitiatorId         = this.GetCurrentUserId()
        };
        var result = _shoppingListService.DeleteShoppingListEntry(model);

        return(Response(result));
    }
    public IOutputModel DeleteShoppingListEntry(DeleteShoppingListEntryInput model)
    {
        var entry =
            _shoppingListEntryRepository.Get(
                q => q.Filter(e => e.Id == model.ShoppingListEntryId).Include(e => e.ShoppingList).Take(1))
            .SingleOrDefault();

        if (entry == null)
        {
            return(Output(OperationResult.NotFound));
        }
        if (entry.ShoppingList.OwnerId != model.InitiatorId)
        {
            return(Output(OperationResult.AccessDenied));
        }
        if (entry.ShoppingListId != model.ShoppingListId)
        {
            return(Output(OperationResult.BadRequest));
        }
        _shoppingListEntryRepository.Delete(entry);
        return(SuccessOutput());
    }