public void PostRatings(RatingInformationDTO RatingToAdd) { var user = RequestContext.Principal; //try //{ foreach (RatingDTO rating in RatingToAdd.Ratings) { Models.Rating newRating = new Models.Rating(); newRating.ProductID = RatingToAdd.ProductID; newRating.userID = user.Identity.Name; newRating.RatingCategory = rating.RatedArea; newRating.rating = rating.Score; //db.RatingDetails.Add(newRating); db.SaveChanges(); } // do stuff to store the rating here //catch (Exception ex) //{ // throw new Exception("Cannot add a rating", ex); //} }
public IHttpActionResult PostRating(RatingInformationDTO RatingToAdd) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = RequestContext.Principal; //try //{ foreach (RatingDTO rating in RatingToAdd.Ratings) { Models.Rating newRating = new Models.Rating(); newRating.ProductID = RatingToAdd.ProductID; newRating.userID = user.Identity.Name; newRating.RatingCategory = rating.RatedArea; newRating.rating = rating.Score; if (db.Ratings.Any(x => x.ProductID == newRating.ProductID && x.userID == newRating.userID && x.RatingCategory == newRating.RatingCategory)) { db.Ratings.Single(x => x.ProductID == newRating.ProductID && x.userID == newRating.userID && x.RatingCategory == newRating.RatingCategory).rating = newRating.rating; } else { db.Ratings.Add(newRating); } db.SaveChanges(); } //db.Ratings.Add(rating); //try //{ // db.SaveChanges(); // } //catch (DbUpdateException) // { // if (RatingExists(rating.userID)) // { // return Conflict(); // } // else // { // throw; // } // } return(CreatedAtRoute("DefaultApi", new { id = RatingToAdd.ProductID }, RatingToAdd)); }
public void SendRatings(RatingInformationDTO Ratings) { client.Authenticator = new NtlmAuthenticator(); client.AddDefaultHeader("Host", "localhost:12672"); client.AddDefaultHeader("Cache-Control", "max-age=0"); client.AddDefaultHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); client.AddDefaultHeader("Upgrade-Insecure-Requests", "1"); client.AddDefaultHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36"); client.AddDefaultHeader("Accept-Encoding", "gzip, deflate, sdch"); client.AddDefaultHeader("Accept-Language", "en-GB,en;q=0.8,en-US;q=0.6"); var request = new RestRequest("PostRatings", Method.POST); request.RequestFormat = DataFormat.Json; request.AddBody(Ratings); var response = client.Execute <RatingInformationDTO>(request); }
static void Main(string[] args) { // from the service - a ratingsInformation object will be sent to the user: API_Proxy api = new API_Proxy("http://localhost.fiddler:12672/api/StoreContent"); RatingInformationDTO RI = api.GetRatingsInformation(); // Set up application RI.ProductID = 1; bool Running = true; System.ConsoleKeyInfo menuup; int selected = 0; do { Console.Clear(); Console.WriteLine("Open GI Feed Back"); int render = 0; foreach (var item in RI.Ratings) { Console.ResetColor(); if (render == selected) { Console.BackgroundColor = ConsoleColor.Blue; Console.ForegroundColor = ConsoleColor.White; } Console.WriteLine(item.RatedArea + StarRatingString(item.Score, item.OutOf)); render = render + 1; Console.ResetColor(); } menuup = Console.ReadKey(true); switch (menuup.Key) { case ConsoleKey.Escape: Running = false; //ShutdownRobot(); return; case ConsoleKey.UpArrow: if (selected > 0) { selected--; } break; case ConsoleKey.RightArrow: if (RI.Ratings[selected].Score < RI.Ratings[selected].OutOf) { RI.Ratings[selected].Score++; } break; case ConsoleKey.LeftArrow: if (RI.Ratings[selected].Score > 0) { RI.Ratings[selected].Score--; } break; case ConsoleKey.DownArrow: if (selected < RI.Ratings.Count() - 1) { selected++; } break; case ConsoleKey.Enter: Running = false; api.SendRatings(RI); break; } }while (Running); }