// // GET: /MyFriend/ public ActionResult Index() { // Get the id in the cookie var cookie = Request.Cookies["User"]; var userId = ""; if (cookie != null) userId = cookie["UserId"]; // Display all his friends var allfriends = db.Friends.SqlQuery(@"SELECT * FROM Friends WHERE UserId = {0}", userId).ToList(); // Add them to a list var model = new MyFriendModel {ListUsers = new List<User>()}; model.ListUsers.AddRange(allfriends.Select(friend => db.Users.Find(friend.HisFriendId))); return View(model); }
// GET: /Event/Participant/5 public ActionResult Participant(int? id) { // Get the id in the cookie var cookie = Request.Cookies["User"]; var userid = 0; if (cookie != null) userid = int.Parse(cookie["UserId"]); if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } // If he participates to the event var myevent = db.UserEvents.FirstOrDefault(ue => ue.EventId == id && ue.UserId == userid); if (myevent == null) { return HttpNotFound(); } // Find all the participant var userevent = db.UserEvents.SqlQuery(@"SELECT * FROM UserEvents WHERE EventId = {0}", id).ToList(); var model = new MyFriendModel {ListUsers = new List<User>()}; // Add each participant to a list foreach (var ue in userevent) { model.ListUsers.Add(db.Users.FirstOrDefault(u => u.UserId == ue.UserId)); } return View(model); }