public JsonResult GetComments(string id) { MongodbFunctions mongo = new MongodbFunctions(); ObjectId objID = new ObjectId(id); Database.DomainModel.Product product = mongo.GetProduct(objID); List <MongoDBRef> mess = product.Messages; int count = product.Messages.Count; string role; if (User.IsInRole("Admin")) { role = "Admin"; } else { role = "User"; } List <Database.DomainModel.MessageShow> comments = new List <Database.DomainModel.MessageShow>(); List <Database.DomainModel.UserShow> users = new List <Database.DomainModel.UserShow>(); foreach (MongoDBRef r in mess) { Database.DomainModel.Message comment = mongo.GetComment(new ObjectId(r.Id.ToString())); Database.DomainModel.User user = mongo.GetUser(new ObjectId(comment.User.Id.ToString())); List <string> responses = new List <string>(); foreach (MongoDBRef rr in comment.Responses) { Database.DomainModel.AdminResponse response = mongo.GetResponse(new ObjectId(rr.Id.ToString())); responses.Add(response.Content); } Database.DomainModel.MessageShow messShow = new Database.DomainModel.MessageShow { Id = comment.Id.ToString(), Content = comment.Content, Responses = responses }; 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 }; comments.Add(messShow); users.Add(userShow); } return(Json(new { number = count, status = role, com = comments, people = users }, JsonRequestBehavior.AllowGet)); }
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)); }