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 }); } }
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 }); } }
public ActionResult Put(int id, [FromForm] ItemReviewDto itemDto) { return(GetStatusCodeResult(_itemsReviewManager.Update(itemDto, id))); }
public ActionResult Post([FromForm] ItemReviewDto itemDto) { return(GetStatusCodeResult(_itemsReviewManager.Insert(itemDto))); }