//public ActionResult EditProfile(UserModel user) //{ // if (ModelState.IsValid) // { // Claim sessionName = ClaimsPrincipal.Current.FindFirst(ClaimTypes.Name); // string userName = sessionName.Value; // UserModel userModel = db.userModel.FirstOrDefault(u => u.Username.Equals(userName)); // userModel.NewPassword = user.NewPassword; // userModel.ConfirmPassword = user.ConfirmPassword; // userModel.Email = user.Email; // db.Entry(userModel).State = EntityState.Modified; // db.SaveChanges(); // return RedirectToAction("Index"); // } // return View(user); //} //GET: UserModels/Edit/5 public ActionResult Edit(int?id) { UserModel userModel = db.userModel.Include(s => s.Files).SingleOrDefault(s => s.UserID == id); var c = new LoggInController(); try { var loggedInUser = LoggInController.GetUserId();/*(HttpContext.Current.User.Identity.Name);*/ if (id != loggedInUser) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } else { return(View(userModel)); } //if (id == null) // { // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); // } //if (userModel == null) //{ // return HttpNotFound(); //} } catch (Exception e) { Console.WriteLine(e); } return(View(userModel)); }
public ActionResult AcceptFriendRequest(int id) { var a = from f in db.Friend where f.FriendId == id select new { f.Fid }; if (a.Equals(LoggInController.GetUserId())) { Friend friend = db.Friend.Find(id); friend.RequestAccepted = true; try { db.Entry(friend).State = EntityState.Modified; db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } } else { return(new HttpStatusCodeResult(404, "Done")); } return(RedirectToAction("showFriendRequest")); }
public ActionResult showFriendRequest() { int id = LoggInController.GetUserId(); var joinQuery = from user in db.userModel join friend in db.Friend on user.UserID equals friend.UserId where friend.RequestAccepted == false && friend.Fid == id select new { user.FirstName, user.LastName, user.Username, user.UserID }; var users = new List <UserModel>(); foreach (var t in joinQuery) { users.Add(new UserModel() { FirstName = t.FirstName, LastName = t.LastName, Username = t.Username, UserID = t.UserID, }); } return(View(users)); }
public string AddFriend(int friendId) { OurDbContext db = new OurDbContext(); int Uid = LoggInController.GetUserId(); var getFriendConnection = db.Friend.Where(u => u.Fid == friendId && u.UserId == Uid).Select(u => u.UserId); var materializeFriend = getFriendConnection.ToList(); bool isEmptyFriend = !materializeFriend.Any(); try { if (Uid == friendId) { //return new HttpStatusCodeResult(@ViewBag.Message = "Du kan inte vara vän med sig själv"); //return (ViewBag.Message = "Du kan inte vara vän med dig själv"); //@ViewBag.Message = "Du kan inte vara vän med dig själv."; return(ViewBag.Friend = "Du kan inte vara vän med dig själv"); } else if (isEmptyFriend) { var userToUpdate = db.userModel.Find(Uid); var oneFriend = new Friend { UserId = Uid, Fid = friendId }; userToUpdate.Friends = new List <Friend> { oneFriend }; db.Entry(userToUpdate).State = EntityState.Modified; db.SaveChanges(); return(ViewBag.Friend = "Ni är nu vänner"); //return new HttpStatusCodeResult(404, "Done"); } else if (!isEmptyFriend) { return(ViewBag.Friend = "Ni är redan vänner"); //return new HttpStatusCodeResult(404, "You are already friends"); } } catch (Exception e) { Console.WriteLine(e); } return(ViewBag.Friend = "Hejhej"); //return View("~/Home"); //return Redirect("~/Home"); //return new HttpStatusCodeResult(404, "Hejsan"); //return ViewBag.Message = "Hejsan hoppsan"; }
public ActionResult checkFReq() { int id = LoggInController.GetUserId(); int Request = (from user in db.userModel join friend in db.Friend on user.UserID equals friend.UserId where friend.RequestAccepted == false && friend.Fid == id select user).Count(); if (Request > 0) { return(Json("Success")); } return(Json("An Error Has occoured")); }