Example #1
0
        public ResultMessage Update(ItemReviewDto itemReviewDto, int id)
        {
            var validationResult = _validator.Validate(itemReviewDto);

            if (!validationResult.IsValid)
            {
                return new ResultMessage
                       {
                           Status             = HttpStatusCode.BadRequest,
                           ValidationMessages = validationResult.GetErrorsList()
                       }
            }
            ;

            try
            {
                var oldItem = _unitOfWork.ItemsReviewsRepository.GetById(id);

                if (oldItem != null)
                {
                    if (itemReviewDto.ProfilePictureFile != null)
                    {
                        itemReviewDto.ProfilePicture = _attachmentsManager.Save(new SavedFileDto
                        {
                            attachmentType = AttachmentTypesEnum.Products,
                            CanChangeName  = true,
                            File           = itemReviewDto.ProfilePictureFile
                        });
                    }

                    oldItem.Name = itemReviewDto.Name;

                    oldItem.ProfilePicture = itemReviewDto.ProfilePicture;
                    _unitOfWork.ItemsReviewsRepository.Update(oldItem);
                    _unitOfWork.Commit();
                    return(new ResultMessage
                    {
                        Status = HttpStatusCode.OK
                    });
                }
                else
                {
                    return(new ResultMessage
                    {
                        Status = HttpStatusCode.NotFound,
                        ErrorCode = (int)ItemsReviewsErrorsCodeEnum.ItemsNotFoundError
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage
                {
                    Status = HttpStatusCode.InternalServerError,
                    ErrorCode = (int)ItemsReviewsErrorsCodeEnum.ItemsUpdateError
                });
            }
        }
Example #2
0
        public ResultMessage Insert(ItemReviewDto newItemDto)
        {
            var validationResult = _validator.Validate(newItemDto);

            if (!validationResult.IsValid)
            {
                return new ResultMessage
                       {
                           Status             = HttpStatusCode.BadRequest,
                           ValidationMessages = validationResult.GetErrorsList()
                       }
            }
            ;

            try
            {
                if (newItemDto.ProfilePictureFile != null)
                {
                    newItemDto.ProfilePicture = _attachmentsManager.Save(new SavedFileDto
                    {
                        attachmentType = AttachmentTypesEnum.Products,
                        CanChangeName  = true,
                        File           = newItemDto.ProfilePictureFile
                    });
                }

                _unitOfWork.ItemsReviewsRepository.Insert(newItemDto.Adapt <ItemsForReview>());

                _unitOfWork.Commit();

                return(new ResultMessage()
                {
                    Status = HttpStatusCode.OK
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage()
                {
                    ErrorCode = (int)ItemsReviewsErrorsCodeEnum.ItemsInsertError,
                    Status = HttpStatusCode.InternalServerError
                });
            }
        }
Example #3
0
 public ActionResult Put(int id, [FromForm] ItemReviewDto itemDto)
 {
     return(GetStatusCodeResult(_itemsReviewManager.Update(itemDto, id)));
 }
Example #4
0
 public ActionResult Post([FromForm] ItemReviewDto itemDto)
 {
     return(GetStatusCodeResult(_itemsReviewManager.Insert(itemDto)));
 }