public IHttpActionResult PostUser_Friends(User_Friends user_Friends) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.User_Friends.Add(user_Friends); try { db.SaveChanges(); } catch (DbUpdateException) { if (User_FriendsExists(user_Friends.user_id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = user_Friends.user_id }, user_Friends)); }
public IHttpActionResult PutUser_Friends(int id, User_Friends user_Friends) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != user_Friends.user_id) { return(BadRequest()); } db.Entry(user_Friends).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!User_FriendsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetUser_Friends(int id) { User_Friends user_Friends = db.User_Friends.Find(id); if (user_Friends == null) { return(NotFound()); } return(Ok(user_Friends)); }
public IHttpActionResult DeleteUser_Friends(int id) { User_Friends user_Friends = db.User_Friends.Find(id); if (user_Friends == null) { return(NotFound()); } db.User_Friends.Remove(user_Friends); db.SaveChanges(); return(Ok(user_Friends)); }
//user/addfriend/2 public ActionResult AddFriend(int id) { try { HttpResponseMessage response = UserClient.GetAsync($"api/users/{Session["user_id"]}").Result; User me = response.Content.ReadAsAsync <User>().Result; HttpResponseMessage FriendResponse = UserClient.GetAsync("api/users/" + id).Result; User Friend = FriendResponse.Content.ReadAsAsync <User>().Result; if (response.IsSuccessStatusCode) { User_Friends MeAsUserFriend = new User_Friends { user_id = (int)Session["user_id"], user_friend_id = id, request = false }; //Add Relation Between Users In User_Friends Table HttpResponseMessage Postresponse = UserClient.PostAsJsonAsync($"api/user_friends", MeAsUserFriend).Result; } else { return(View("AddFriendError")); } if (FriendResponse.IsSuccessStatusCode) { User_Friends FriendAsUserFriend = new User_Friends { user_id = id, user_friend_id = (int)Session["user_id"], request = false }; //Add Relation Between Users In User_Friends Table HttpResponseMessage Postresponse1 = UserClient.PostAsJsonAsync($"api/user_friends", FriendAsUserFriend).Result; } else { return(View("AddFriendError")); } return(View("Index")); //return RedirectToAction("ViewUserProfile", "User", id); } catch (Exception) { return(View("Error")); } }
public IHttpActionResult DeleteUser_Friends(int Myid, int Id) { User_Friends user_Friends = db.User_Friends.FirstOrDefault(p => p.user_id == Myid && p.user_friend_id == Id); User_Friends user_Friends1 = db.User_Friends.FirstOrDefault(p => p.user_id == Id && p.user_friend_id == Myid); if (user_Friends == null || user_Friends1 == null) { return(NotFound()); } db.User_Friends.Remove(user_Friends); db.User_Friends.Remove(user_Friends1); db.SaveChanges(); return(Ok(user_Friends)); }
public void Set_friendInfo(User_Friends _userFriend) { userFriend = _userFriend; ApplyInfo(); }