/// <summary> /// Method that will update a review if need be /// </summary> /// <param name="review"></param> public void UpdateReview(DriverReview review) { var originalReview = _repo.Query <DriverReview>().Where(o => o.Id == review.Id).FirstOrDefault(); originalReview.Message = review.Message; _repo.Update <DriverReview>(originalReview); }
/// <summary> /// Method to add a review to a list within a ApplicationUser /// </summary> /// <param name="Id"></param> /// <param name="review"></param> /// <param name="sp"></param> public async void AddDriverReview(string Id, DriverReview review, IServiceProvider sp) { var _db = sp.GetService <ApplicationDbContext>(); var result = await Get(review.Message); //Adds sentiment info flattened data to a driver review review.SentimentEntities = new List <SentimentInfo>(); foreach (var r in result) { var sent = new SentimentInfo() { SentimentScore = r.sentiment.score, SentimentType = r.sentiment.type }; review.SentimentEntities.Add(sent); } review.TimeCreated = DateTime.Now; var user = _db.Users.Where(u => u.Id == Id).Include(u => u.Reviews).FirstOrDefault(); user.Reviews.Add(review); _db.SaveChanges(); }
/// <summary> /// The example referes to the process of the uploading a driver review. /// </summary> public void CreateDriverReview() { var route4Me = new Route4MeManagerV5(ActualApiKey); var newDriverReview = new DriverReview() { TrackingNumber = "NDRK0M1V", // TO DO: take this value from generated test route later. Rating = 4, Review = "Test Review" }; var driverReview = route4Me.CreateDriverReview(newDriverReview, out ResultResponse resultResponse); PrintDriverReview(driverReview, resultResponse); }
public IActionResult Post(string id, [FromBody] DriverReview driverReview) { if (ModelState.IsValid) { if (driverReview.Id == 0) { _repo.AddDriverReview(id, driverReview, HttpContext.ApplicationServices); } else { _repo.UpdateReview(driverReview); } return(Ok(driverReview)); } return(HttpBadRequest(ModelState)); }
/// <summary> /// The example referes to the process of the updating a driver review. /// </summary> public void UpdateDriverReview() { var route4Me = new Route4MeManagerV5(ActualApiKey); var existingReview = GetLastDriverReview(); var driverReview = new DriverReview() { RatingId = existingReview.RatingId, TrackingNumber = existingReview.TrackingNumber, Rating = existingReview.Rating, Review = "Updated Review" }; var updatedDriverReview = route4Me.UpdateDriverReview( driverReview, HttpMethodType.Patch, // other availbale option is the Put method out ResultResponse resultResponse); PrintDriverReview(updatedDriverReview, resultResponse); }