public void AddReview(string id, double grade, string comment) { MongodbFunctions mongo = new MongodbFunctions(); Database.DomainModel.Review newReview = new Database.DomainModel.Review { Grade = grade, Comment = comment, Product = new MongoDBRef("products", new ObjectId(id)) }; mongo.AddReview(newReview, id, User.Identity.Name); }
public JsonResult GetReviews(string id) { MongodbFunctions mongo = new MongodbFunctions(); ObjectId objID = new ObjectId(id); Database.DomainModel.Product product = mongo.GetProduct(objID); List <MongoDBRef> rev = product.Reviews; int count = product.Reviews.Count; List <Database.DomainModel.ReviewShow> reviews = new List <Database.DomainModel.ReviewShow>(); List <Database.DomainModel.UserShow> users = new List <Database.DomainModel.UserShow>(); foreach (MongoDBRef r in rev) { Database.DomainModel.Review review = mongo.GetReview(new ObjectId(r.Id.ToString())); Database.DomainModel.User user = mongo.GetUser(new ObjectId(review.User.Id.ToString())); Database.DomainModel.UserShow userShow = new Database.DomainModel.UserShow { Id = user.Id, Name = user.Name, Surname = user.Surname, Email = user.Email, Phone = user.Phone, Address = user.Address }; Database.DomainModel.ReviewShow reviewShow = new Database.DomainModel.ReviewShow { Id = review.Id, Grade = review.Grade, Comment = review.Comment }; reviews.Add(reviewShow); users.Add(userShow); } return(Json(new { number = count, revs = reviews, people = users }, JsonRequestBehavior.AllowGet)); }