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())); }
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 }); }
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")); } }
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()); }
public async Task <Result <ReviewGet> > PostReview(ReviewPost model) { return(await Post <ReviewGet, ReviewPost>(model, "api/v1/reviews")); }
public void Update(ReviewPost reviewPost) { _context.Entry(reviewPost).State = EntityState.Modified; _context.SaveChanges(); }
public void Add(ReviewPost reviewPost) { reviewPost.CreateDateTime = DateTime.Now; _context.Add(reviewPost); _context.SaveChanges(); }
public IActionResult Post(ReviewPost reviewPost) { _reviewPostRepository.Add(reviewPost); return(CreatedAtAction("Get", new { id = reviewPost.Id }, reviewPost)); }