Exemple #1
0
        public async Task <ReviewDTO> CreateReviewAsync(string originalDescription, int businessUnitId, int rating)
        {
            businessValidator.IsDescriptionInRange(originalDescription);
            businessValidator.IsRatingInRange(rating);

            //automatic edit
            var editedDescription = reviewEditor.AutomaticReviewEditor(originalDescription);

            //check visibility
            var checkVisibility = reviewEditor.CheckReviewVisibility(editedDescription);

            var review = new Review()
            {
                OriginalDescription = originalDescription,
                EditedDescription   = editedDescription,
                Rating         = rating,
                CreatedOn      = DateTime.Now,
                isVisible      = checkVisibility,
                BusinessUnitId = businessUnitId
            };

            this.context.Reviews.Add(review);

            await this.context.SaveChangesAsync();

            var result = await this.context.Reviews
                         .Include(bu => bu.BusinessUnit)
                         .FirstOrDefaultAsync(x => x.Id == review.Id);

            return(result.ToDTO());
        }