コード例 #1
0
ファイル: ReviewController.cs プロジェクト: CNParent/tcr
        public async Task <IActionResult> PostReview(ReviewPost model)
        {
            if (!await Services.Context.Ratings.AnyAsync(x => x.RatingId.Equals(model.RatingId)))
            {
                ModelState.AddModelError(nameof(model.RatingId), Message.NotFound.ToString());
            }

            if (!await Services.Context.Services.AnyAsync(x => x.ServiceId == model.ServiceId.Value))
            {
                ModelState.AddModelError(nameof(model.ServiceId), Message.NotFound.ToString());
            }

            if (!await Services.Context.Users.AnyAsync(x => x.UserId.Equals(model.UserId)))
            {
                ModelState.AddModelError(nameof(model.UserId), Message.NotFound.ToString());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var entity = model.AsEntity();
            await Services.Context.Reviews.AddAsync(entity);

            await Services.Context.SaveChangesAsync();

            entity = await Services.Reviews.Get(entity.ReviewId);

            return(CreatedAtAction(nameof(GetReview), new { id = entity.ReviewId }, entity.AsModel()));
        }
コード例 #2
0
 public static Review AsEntity(this ReviewPost model)
 {
     return(new Review
     {
         Comment = model.Comment,
         RatingId = model.RatingId,
         ServiceId = model.ServiceId.Value,
         UserId = model.UserId,
         CreatedOn = DateTime.Now
     });
 }
コード例 #3
0
 public IActionResult PostReview([FromBody] ReviewPost reviewData)
 {
     if (ModelState.IsValid)
     {
         return(Ok(_reviewCommandService.PostReview(reviewData.CompanyId, CustomAuthorizationHelper.GetCurrentUserId(User), reviewData.Stars, reviewData.WrittenReview, reviewData.Anonymous, reviewData.IsReview)));
     }
     else
     {
         return(BadRequest("Review information is incomplete"));
     }
 }
コード例 #4
0
        public IActionResult Put(int id, ReviewPost reviewPost)
        {
            var currentUserProfile = GetCurrentUserProfile();

            if (currentUserProfile.Id != reviewPost.UserProfileId)
            {
                return(Unauthorized());
            }

            if (id != reviewPost.Id)
            {
                return(BadRequest());
            }

            _reviewPostRepository.Update(reviewPost);
            return(NoContent());
        }
コード例 #5
0
ファイル: TcrClient.cs プロジェクト: CNParent/tcr
 public async Task <Result <ReviewGet> > PostReview(ReviewPost model)
 {
     return(await Post <ReviewGet, ReviewPost>(model, "api/v1/reviews"));
 }
コード例 #6
0
 public void Update(ReviewPost reviewPost)
 {
     _context.Entry(reviewPost).State = EntityState.Modified;
     _context.SaveChanges();
 }
コード例 #7
0
 public void Add(ReviewPost reviewPost)
 {
     reviewPost.CreateDateTime = DateTime.Now;
     _context.Add(reviewPost);
     _context.SaveChanges();
 }
コード例 #8
0
 public IActionResult Post(ReviewPost reviewPost)
 {
     _reviewPostRepository.Add(reviewPost);
     return(CreatedAtAction("Get", new { id = reviewPost.Id }, reviewPost));
 }