public async Task <dynamic> addIgnored([FromBody] IgnoredDTO ignoreReq) { AccountIgnored existingIgnored = db.AccountIgnored.Where(af => af.AccountId == ignoreReq.AccountId && af.IgnoredAccountId == ignoreReq.IgnoredAccountId).FirstOrDefault(); AccountFriend existingFriend = db.AccountFriend.Where(af => af.AccountId == ignoreReq.AccountId && af.FriendAccountId == ignoreReq.IgnoredAccountId).FirstOrDefault(); if (existingIgnored != null) { return(StatusCode(403, "This player is already ignored.")); } if (existingFriend != null) { db.AccountFriend.Attach(existingFriend); db.Entry(existingFriend).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } AccountIgnored newIgnore = new AccountIgnored() { AccountId = ignoreReq.AccountId, IgnoredAccountId = ignoreReq.IgnoredAccountId, CreateDt = DateTime.UtcNow }; db.AccountIgnored.Add(newIgnore); db.SaveChanges(); return(Ok("Player Ignored")); }
public async Task <dynamic> addBuddy([FromBody] BuddyDTO buddyReq) { AccountFriend existingFriend = db.AccountFriend.Where(af => af.AccountId == buddyReq.AccountId && af.FriendAccountId == buddyReq.BuddyAccountId).FirstOrDefault(); AccountIgnored existingIgnored = db.AccountIgnored.Where(af => af.AccountId == buddyReq.AccountId && af.IgnoredAccountId == buddyReq.BuddyAccountId).FirstOrDefault(); if (existingFriend != null) { return(StatusCode(403, "Buddy already exists.")); } if (existingIgnored != null) { db.AccountIgnored.Attach(existingIgnored); db.Entry(existingIgnored).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } AccountFriend newFriend = new AccountFriend() { AccountId = buddyReq.AccountId, FriendAccountId = buddyReq.BuddyAccountId, CreateDt = DateTime.UtcNow }; db.AccountFriend.Add(newFriend); db.SaveChanges(); return(Ok("Buddy Added")); }
public async Task <dynamic> removeBuddy([FromBody] BuddyDTO buddyReq) { AccountFriend existingFriend = db.AccountFriend.Where(af => af.AccountId == buddyReq.AccountId && af.FriendAccountId == buddyReq.BuddyAccountId).FirstOrDefault(); if (existingFriend == null) { return(StatusCode(403, "Cannot remove a buddy that isn't a buddy.")); } db.AccountFriend.Attach(existingFriend); db.Entry(existingFriend).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; db.SaveChanges(); return(Ok("Buddy Removed")); }
public TransitAccountActivity GetTransformedInstanceFromAccountFriend(ISession session, ManagedSecurityContext sec, AccountFriend friend) { ManagedAccountActivity m_instance = new ManagedAccountActivity(); m_instance.SetInstance(session, (friend.Account.Id != mInstance.Id) ? friend.Account : friend.Keen); return(m_instance.GetTransitInstance(sec)); }
public int CreateAccountWithInvitation(int invitationid, string code, TransitAccount ta) { using (SnCore.Data.Hibernate.Session.OpenConnection()) { ISession session = SnCore.Data.Hibernate.Session.Current; ManagedAccountInvitation invitation = new ManagedAccountInvitation(session, invitationid); if (invitation.Code != code) { throw new ManagedAccount.AccessDeniedException(); } ManagedAccount acct = new ManagedAccount(session); int id = acct.Create(invitation.Instance.Email, ta, true, ManagedAccount.GetAdminSecurityContext(session)); // become friends with the person who invited you TransitAccountFriend t_friend = new TransitAccountFriend(); AccountFriend friend = new AccountFriend(); friend.Account = session.Load<Account>(invitation.AccountId); friend.Keen = session.Load<Account>(id); friend.Created = DateTime.UtcNow; session.Save(friend); SnCore.Data.Hibernate.Session.Flush(); // notify that a friend has joined ManagedAccount recepient = new ManagedAccount(session, invitation.AccountId); ManagedSiteConnector.TrySendAccountEmailMessageUriAsAdmin(session, recepient, string.Format("EmailAccountInvitationAccept.aspx?id={0}&aid={1}", invitation.Id, id)); // if this is a group invitation, join the group if (invitation.Instance.AccountGroup != null) { AccountGroupAccountInvitation groupInvitation = new AccountGroupAccountInvitation(); groupInvitation.Account = session.Load<Account>(id); groupInvitation.AccountGroup = invitation.Instance.AccountGroup; groupInvitation.Created = invitation.Instance.Created; groupInvitation.Modified = invitation.Instance.Modified; groupInvitation.Requester = session.Load<Account>(invitation.AccountId); ManagedAccountGroupAccountInvitation mGroupInvitation = new ManagedAccountGroupAccountInvitation( session, groupInvitation); mGroupInvitation.JoinGroup(ManagedAccount.GetAdminSecurityContext(session), string.Empty); } invitation.Delete(ManagedAccount.GetAdminSecurityContext(session)); SnCore.Data.Hibernate.Session.Flush(); return acct.Id; } }