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 void AddResponse(string id, string content) { MongodbFunctions mongo = new MongodbFunctions(); ObjectId messId = new ObjectId(id); Database.DomainModel.AdminResponse newResponse = new Database.DomainModel.AdminResponse { Content = content, Message = new MongoDBRef("messages", messId) }; mongo.AddResponse(newResponse, messId); }