public static ProductVote ToEntity(this AddProductCommentDto source, string userId) { return(new ProductVote { Comment = source.Comment, ProductId = source.ProductId, UserId = userId }); }
public ServiceResult AddCommentForProduct(AddProductCommentDto dto, string userId) { var serviceResult = dto.IsValid(); if (serviceResult.IsSuccess) { if (_dbContext.Products.Any(c => c.Id == dto.ProductId)) { var entity = dto.ToEntity(userId); entity.Date = DateTime.Now; entity.Stats = VoteState.Wating; Insert(entity); serviceResult = Save("نظر با موفقیت ثبت شد"); } else { serviceResult.AddError("محصولی یافت نشد"); } } return(serviceResult); }