Пример #1
0
        public async Task <IActionResult> IsPostUserFavorite(int postId, string userId)
        {
            var post = await postRepository.GetPost(postId);

            var user = await appUserRepository.GetUser(userId);

            if (post == null || user == null)
            {
                return(NotFound());
            }

            var favorite = await favoriteRepository.GetFavorite(postId, userId);

            if (favorite == null)
            {
                return(Ok(false));
            }
            else
            {
                return(Ok(true));
            }
        }
Пример #2
0
        public async Task <ActionResult <IEnumerable <Favorite> > > GetFavorite()
        {
            try
            {
                var Favorite = await _repository.GetFavorite();

                return(Ok(Favorite));
            }
            catch (Exception exc)
            {
                _logger.LogError($"Error: {exc}");
                // transaction.Rollback();
                return(NotFound());
            }
        }
Пример #3
0
        public Domain.Models.Favorite GetFavorite(int favoriteId)
        {
            _logger.LogInformation($"BEGIN GetFavorite");
            try
            {
                var favorite = _favoriteRepository.GetFavorite(favoriteId);

                if (favorite == null)
                {
                    return(null);
                }

                var productMultilingual = _productRepository.GetProduct(favorite.Product.Id);

                var result = new Domain.Models.Favorite
                {
                    Id      = favorite.Id,
                    UserId  = Guid.Parse(favorite.UserId),
                    Name    = favorite.Name,
                    Product = new Product
                    {
                        Id          = favorite.ProductId,
                        Name        = productMultilingual.Name,
                        VirtualName = productMultilingual.Name.RemoveDiacritics(),
                        Modified    = favorite.Product.Modified,
                        Risk        = new Risk
                        {
                            Description = productMultilingual.Product.Risk.RisksMultilingual.FirstOrDefault(rm => rm.LanguageId == LanguageId).Description,
                            Id          = productMultilingual.Product.Risk.Id,
                            Modified    = productMultilingual.Product.Risk.Modified,
                            Name        = productMultilingual.Product.Risk.RisksMultilingual.FirstOrDefault(rm => rm.LanguageId == LanguageId).Name
                        },
                        Description = productMultilingual.Description
                    }
                };
                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Exception on GetBrand with message: {ex.Message}");
                return(null);
            }
        }
Пример #4
0
        public async Task <ResponseModel <Favorite> > DeleteFavoriteAsync(Guid clientId, Guid productId)
        {
            try
            {
                var targetFavorite = await _favoriteRepository.GetFavorite(clientId, productId);

                if (targetFavorite is null)
                {
                    return(new ResponseModel <Favorite>(true, new List <ErrorInfo>
                    {
                        new ErrorInfo(HttpStatusCode.NotFound, _messages.NoFavoriteFound,
                                      string.Format(_messages.NoFavoriteFoundDescription, clientId, productId))
                    }));
                }

                var deleted = await _favoriteRepository.Delete(targetFavorite);

                if (deleted == 0)
                {
                    return(new ResponseModel <Favorite>(true, new List <ErrorInfo>
                    {
                        new ErrorInfo(HttpStatusCode.Conflict, _messages.NoFavoriteChanged, _messages.NoFavoriteChangedDescription)
                    }));
                }

                return(new ResponseModel <Favorite>(targetFavorite));
            }
            catch (Exception ex)
            {
                var message = string.Format(_messages.InternalErrorDescription, ex.Message);
                _logger.LogError(ex, message);

                return(new ResponseModel <Favorite>(true, new List <ErrorInfo>
                {
                    new ErrorInfo(HttpStatusCode.InternalServerError, _messages.InternalError, message)
                }));
            }
        }
Пример #5
0
        public async Task <ActionResult <GetFavoriteModel> > GetFavorite(string id)
        {
            try
            {
                if (!Guid.TryParse(id, out Guid favoriteId))
                {
                    throw new GuidException("Invalid id", this.GetType().Name, "GetFavorite", "400");
                }

                return(await _favoriteRepository.GetFavorite(id));
            }
            catch (MovieMindException e)
            {
                if (e.MovieMindError.Status.Equals("404"))
                {
                    return(NotFound(e.MovieMindError));
                }
                else
                {
                    return(BadRequest(e.MovieMindError));
                }
            }
        }