public async Task <IEnumerable <FriendRequest> > GetAllFriendRequstsAsync() { return(await FriendRequests.Where(r => r.FromUserId == CurrentUser.Id || r.ToUserId == CurrentUser.Id) .Include(r => r.FromUser) .Include(r => r.ToUser) .ToListAsync()); }
public ActionResult SendRequest(FriendRequests request, string id) { try { var passViewBag = ""; var userName = User.Identity.Name; var From = db.Users.Single(x => x.UserName == userName); request.FromUser = From; var To = db.Users.Single(x => x.Id == id); request.ToUser = To; //Kollar om dom redan är kompisar if (db.Requests.Count(x => x.FromUser.UserName == From.UserName && x.ToUser.UserName == To.UserName || x.ToUser.UserName == To.UserName && x.FromUser.UserName == From.UserName) == 0) { //Är dom inte det, spara requesten db.Requests.Add(request); db.SaveChanges(); passViewBag = "SentRequest"; //Skickar vidare viewbagen till usercontrollern } else { passViewBag = "AlreadySentRequest"; //Skickar vidare viewbagen till usercontrollern } return(RedirectToAction("UserPage", "User", routeValues: new { id = To.Id, passedViewBag = passViewBag })); } catch { return(View("SendRequestMessage", "FriendRequest")); } }
/// <summary> /// Send a Add request to specific user.. Returns the request /// </summary> /// <param name="toUserId"></param> /// <returns></returns> public async Task <FriendRequest> SendAddFriendRequestAsync(string toUserId) { if (CurrentUser.Id == toUserId) { return(null); } var toUser = await Users.FindAsync(toUserId); if (toUser == null || (await GetAllContactsAsync()).Any(x => x.Id == toUserId)) { return(null); } await Db.Entry(CurrentUser).Collection(u => u.FriendRequestsFrom).LoadAsync(); if (CurrentUser.FriendRequestsFrom.Any(r => r.ToUserId == toUserId) || (await GetAllFriendRequstsAsync()).Any(f => f.FromUserId == toUser.Id)) { return(null); } FriendRequest request = new FriendRequest() { FromUser = CurrentUser, ToUser = toUser }; (await FriendRequests.AddAsync(request)).State = EntityState.Added; toUser.HasFriendRequest = true; Db.Entry(toUser).State = EntityState.Modified; await Db.SaveChangesAsync(); return(request); }
/// <summary> /// Remove a specific friend request "From or To" /// </summary> /// <param name="id">The specific friend Id</param> public async Task <FriendRequest> RemoveFriendRequestByIdAsync(string requestId) { var friendRequests = await FriendRequests .Include(r => r.FromUser) .Include(r => r.ToUser) .Where(r => r.FromUser.Id == CurrentUser.Id || r.ToUser.Id == CurrentUser.Id).ToListAsync(); var request = friendRequests?.SingleOrDefault(r => r.Id == requestId); if (request == null) { return(null); } var user = (request.ToUserId == CurrentUser.Id) ? request.ToUser : request.FromUser; (FriendRequests.Remove(request)).State = EntityState.Deleted; friendRequests.Remove(request); user.HasFriendRequest = friendRequests.Any(r => r.ToUser.Id == user.Id); Db.Entry(user).State = EntityState.Modified; await Db.SaveChangesAsync(); return(request); }
public int SendFriendRequest(int senderId, int receiverId) { return(ExecuteInTransaction(unit => { // o sterg pe cea veche daca exista si adaug una noua var oldFr = unit.FriendRequests.Get() .FirstOrDefault(fr => (fr.SenderId == senderId && fr.ReceiverId == receiverId) || (fr.SenderId == receiverId && fr.ReceiverId == senderId)); if (oldFr != null) { unit.FriendRequests.Delete(oldFr); } var newFr = new FriendRequests() { SenderId = senderId, ReceiverId = receiverId, CreateDate = DateTime.Now, IsDeleted = false }; unit.FriendRequests.Insert(newFr); return unit.Complete(); })); }
public void UpdateDataView(FriendRequests model) { this._model = model; if (this._model == null || model.count == 0) { return; } if (!model.are_suggested_friends) { this.TitleBlock.Text = (UIStringFormatterHelper.FormatNumberOfSomething(model.count, CommonResources.OneFriendRequestFrm, CommonResources.TwoFourFriendRequestsFrm, CommonResources.FiveFriendRequestsFrm, true, null, false)); } else { this.TitleBlock.Text = (UIStringFormatterHelper.FormatNumberOfSomething(model.count, CommonResources.SuggestedFriendOneFrm, CommonResources.SuggestedFriendTwoFrm, CommonResources.SuggestedFriendFiveFrm, true, null, false)); } ((UIElement)this.ShowAllBlock).Visibility = (model.count > 1 ? Visibility.Visible : Visibility.Collapsed); if (model.requests[0].RequestHandledAction == null) { model.requests[0].RequestHandledAction = (Action <FriendRequests>)(requests => ((FriendsViewModel)base.DataContext).RequestsViewModel = requests); } this.RequestView.Content = (new FriendRequestUC() { Model = model.requests[0], Profiles = model.profiles.ToArray(), IsSuggestedFriend = new bool?(model.are_suggested_friends) }); }
public async Task <IActionResult> Create([Bind("RequestID,Sender,Recipient")] FriendRequests friendRequests, string id) { Profile Recipient = _context.Profile.Single(e => e.UserID == id); if (ModelState.IsValid) { friendRequests.Sender = User.Identity.Name; friendRequests.Recipient = id; bool notEligibleFriends = false; FriendRequests friendRequest = _context.FriendRequests.FirstOrDefault(fr => fr.Recipient == id && fr.Sender == User.Identity.Name); Friends friend = _context.Friends.FirstOrDefault(f => f.User == User.Identity.Name && f.FriendWith == id); Friends friends = _context.Friends.FirstOrDefault(f => f.User == id && f.FriendWith == User.Identity.Name); if (friendRequest != null || friend != null || friends != null) { notEligibleFriends = true; } if (notEligibleFriends == false) { _context.Add(friendRequests); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); } return(View(friendRequests)); }
public IActionResult Create(int id) { FriendRequests friendRequest = _context.FriendRequests.FirstOrDefault(fr => fr.RequestID == id); Profile requestSender = _context.Profile.FirstOrDefault(p => p.UserID == friendRequest.Sender); FriendRequestsController.TargetProfile = requestSender; return(View()); }
public static FriendRequestDto ConvertRequestToDto(FriendRequests request) { var requestDto = new FriendRequestDto(); requestDto.Id = request.Id; requestDto.FromUser = ConvertSingleUserToDto(request.FromUser); requestDto.ToUserId = request.UserId; requestDto.Seen = request.Seen; return(requestDto); }
protected void Page_LoadComplete(object sender, EventArgs e) { UsernameLbl.Text = user.username; ProfilePicture.pictureName = user.picture; FriendRequests.DataSource = BLL_Helper.UserListFromUsernameList(user.UnopenedFriendRequests); FriendRequests.DataBind(); Friends.DataSource = BLL_Helper.UserListFromUsernameList(user.AcceptedFriends); Friends.DataBind(); GameInvites.DataSource = user.activeGameInvites; GameInvites.DataBind(); }
public ActionResult AddFriend(string id) { var friendRequest = new FriendRequests(); friendRequest.UserReceivedId = id; friendRequest.UserSentId = User.Identity.GetUserId(); DbManager.FriendRequests.Add(friendRequest); DbManager.SaveChanges(); return(RedirectToAction("Index", "Home")); }
async Task RefreshAsync() { if (IsBusy) { return; } IsBusy = true; var fake = FriendRequests.Count == 0; try { if (fake) { FriendRequests.Add(new PendingFriendRequest()); OnPropertyChanged(nameof(ShowNoFriends)); } var requests = await DataService.GetFriendRequestsAsync(forceRefresh); forceRefresh = false; FriendRequests.ReplaceRange(requests); SettingsService.LastFriendRequestsUpdate = DateTime.UtcNow; OnPropertyChanged(nameof(LastUpdate)); SettingsService.FriendRequestCount = FriendRequests.Count == 0 ? string.Empty : FriendRequests.Count.ToString(); } catch (HttpResponseException hrex) when(!string.IsNullOrWhiteSpace(hrex.Message)) { if (fake) { FriendRequests.Clear(); } await DisplayAlert("Uh oh, turbulence", hrex.Message); } catch (Exception ex) { if (fake) { FriendRequests.Clear(); } await DisplayAlert("Uh oh, turbulence", "Looks like something went wrong. Check internet and try again."); Crashes.TrackError(ex); } finally { IsBusy = false; } OnPropertyChanged(nameof(ShowNoFriends)); }
async Task ApproveFriendRequest(PendingFriendRequest pendingFriendRequest) { if (IsBusy) { return; } if (!(await CheckConnectivity("Check connectivity", "Unable to update profile, please check internet and try again"))) { return; } if (!await DisplayAlert("Approve friend request?", $"Are you sure you want to approve {pendingFriendRequest.Name}'s request?", "Yes, approve", "Cancel")) { return; } Analytics.TrackEvent("FriendRequest", new Dictionary <string, string> { ["type"] = "approve" }); IsBusy = true; try { await DataService.ApproveFriendRequestAsync(pendingFriendRequest.RequesterPublicKey); FriendRequests.Remove(pendingFriendRequest); DataService.ClearCache(DataService.FriendRequestKey); forceRefresh = true; SettingsService.FriendRequestCount = FriendRequests.Count == 0 ? string.Empty : FriendRequests.Count.ToString(); SettingsService.ForceRefreshFriends = true; } catch (HttpResponseException hrex) when(!string.IsNullOrWhiteSpace(hrex.Message)) { await DisplayAlert("Uh oh, turbulence", hrex.Message); } catch (Exception ex) { await DisplayAlert("Uh oh, turbulence", "Looks like something went wrong. Check internet and try again."); Crashes.TrackError(ex); } finally { IsBusy = false; } OnPropertyChanged(nameof(ShowNoFriends)); }
private void ShowRequestsExecute() { try { FriendRequests requests = new FriendRequests(User); requests.ShowDialog(); FriendList = userService.GetFriends(User); CheckList = FriendList.Select(item => item.UserID).ToList(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
protected override void HandleRequest() { DbAccount acc; var status = Database.Verify(Query["guid"], Query["password"], out acc); if (status == LoginStatus.OK) { WriteLine(FriendRequests.FromDb(Database, acc).ToXml()); } else { WriteLine("<Requests></Requests>"); } }
//The function is used save friend requests public static bool InsertFriendRequest(int fromid, int toid) { var friendrequest = new FriendRequests(); friendrequest.dateaccepted = DateTime.Now; friendrequest.datecreated = DateTime.Now; friendrequest.datemodified = DateTime.Now; friendrequest.status = 0; friendrequest.useridfrom = fromid; friendrequest.useridto = toid; using (UsersContext db = new UsersContext()) { var friendrequests = db.Set <FriendRequests>(); friendrequests.Add(friendrequest); db.SaveChanges(); return(true); } }
public override int GetHashCode() { int hash = 1; if (msgTypeCase_ == MsgTypeOneofCase.FriendsList) { hash ^= FriendsList.GetHashCode(); } if (msgTypeCase_ == MsgTypeOneofCase.FriendDetail) { hash ^= FriendDetail.GetHashCode(); } if (msgTypeCase_ == MsgTypeOneofCase.FriendRequests) { hash ^= FriendRequests.GetHashCode(); } hash ^= (int)msgTypeCase_; return(hash); }
public FriendRequestsViewModel(FriendRequests friendRequests, tblUser userLogedIn) { view = friendRequests; User = userLogedIn; userService = new UserService(); var listOfUsers = userService.GetUsers().Where(u => u.UserID != User.UserID).ToList(); using (SocialNetworkDbEntities context = new SocialNetworkDbEntities()) { tblUser userInDb = (from x in context.tblUsers where x.UserID == User.UserID select x).First(); UserList = userInDb.tblUsers.ToList(); } SelectedUser = UserList.FirstOrDefault(); }
public void SendRequest(SendRequestDto request) { var existingRequest = _friendRequestsRepository.GetFirstWhere(x => x.FromUserId == request.FromUserId && x.UserId == request.ToUserId); if (existingRequest != null) { throw new FlowException("Request already exists!"); } var newRequest = new FriendRequests() { UserId = request.ToUserId, FromUserId = request.FromUserId, Seen = false }; _friendRequestsRepository.Add(newRequest); _friendRequestsRepository.SaveEntities(); }
public async void SetFriends(List <User> friends, FriendRequests requests) { if (friends == null && this._sc != null) { friends = this._sc.SavedUsers; } if (requests == null && this._sc != null) { requests = this._sc.Requests; } SavedContacts savedContacts = new SavedContacts(); savedContacts.SyncedDate = DateTime.UtcNow; savedContacts.SavedUsers = friends; savedContacts.Requests = requests; savedContacts.CurrentUserId = AppGlobalStateManager.Current.LoggedInUserId; this._sc = savedContacts; EventAggregator.Current.Publish(new FriendsCacheUpdated()); await CacheManager.TrySerializeAsync(savedContacts, this.Key, false, CacheManager.DataType.CachedData); }
private void Button_OnClicked(object sender, RoutedEventArgs e) { if (this.Model.RequestHandledAction == null) { return; } string format = "\r\n\r\nvar result=API.friends.{0}({{user_id:{3}}});\r\nif (({1}&&result>0)||({2}&&result.success==1)) \r\n return API.execute.getFriendsWithRequests({{requests_count:1,requests_offset:0,without_friends:1,requests_only:{4},suggested_only:{5}}});\r\nreturn 0;"; object[] objArray = new object[6] { (sender == this.AddButton ? "add" : "delete"), (sender == this.AddButton ? "true" : "false"), (sender == this.AddButton ? "false" : "true"), this.Model.user_id, null, null }; int index1 = 4; bool? isSuggestedFriend; string str1; if (this.NeedBottomSeparatorLine) { isSuggestedFriend = this.IsSuggestedFriend; bool flag = false; if ((isSuggestedFriend.GetValueOrDefault() == flag ? (isSuggestedFriend.HasValue ? 1 : 0) : 0) != 0) { str1 = "1"; goto label_5; } } str1 = "0"; label_5: objArray[index1] = str1; int index2 = 5; string str2; if (this.NeedBottomSeparatorLine) { isSuggestedFriend = this.IsSuggestedFriend; if (isSuggestedFriend.Value) { str2 = "1"; goto label_9; } } str2 = "0"; label_9: objArray[index2] = str2; string str3 = string.Format(format, objArray); FriendRequest model = this.Model; Action <BackendResult <FriendRequests, ResultCode> > action = (Action <BackendResult <FriendRequests, ResultCode> >)(result => Execute.ExecuteOnUIThread((Action)(() => { if (result.ResultCode == ResultCode.Succeeded) { FriendRequests resultData = result.ResultData; model.RequestHandledAction(resultData); CountersManager.Current.Counters.friends = resultData.menu_counter; EventAggregator.Current.Publish((object)new CountersChanged(CountersManager.Current.Counters)); } PageBase.SetInProgress(false); }))); PageBase.SetInProgress(true); string str4 = "execute"; Dictionary <string, string> dictionary = new Dictionary <string, string>(); string key = "code"; string str5 = str3; dictionary.Add(key, str5); // ISSUE: variable of the null type CancellationToken?nullable = new CancellationToken?(); // ISSUE: variable of the null type VKRequestsDispatcher.DispatchRequestToVK <FriendRequests>(str4, dictionary, action, null, false, true, nullable, null); }
private void friends_png_MouseDown(object sender, MouseButtonEventArgs e) { FriendRequests Fq = new FriendRequests(); Fq.Show(); }