Exemple #1
0
        public async Task <Result> DeleteFavoriteProduct(Guid customerId, DeleteFavoriteProductModel model)
        {
            if (!CustomerAuthorizationService.CustomerIdIsAuthorized(customerId))
            {
                return(Result.Forbidden());
            }

            if (await ProductRepository.GetFirstOrDefaultAsync(predicate: c => c.Id == customerId) == null)
            {
                return(Result.NotFound());
            }

            var relationship = await
                               FavoriteProductRepository.GetFirstOrDefaultAsync(
                predicate : fp => fp.ProductId == model.ProductId && fp.CustomerId == customerId);

            if (relationship == null)
            {
                return(Result.NotFound());
            }

            FavoriteProductRepository.Delete(relationship);

            await UnitOfWork.SaveChangesAsync();

            return(Result.Success());
        }
Exemple #2
0
 public async Task <ActionResult> DeleteFavoriteProduct(Guid id, [FromBody] DeleteFavoriteProductModel model)
 {
     return(GetResult(await FavoriteProductService.DeleteFavoriteProduct(id, model)));
 }