示例#1
0
 public OperationResult <UserExt> Authentication(string token)
 {
     Console.WriteLine("AccountUpdateServiceprovider  Auth");
     try
     {
         using (db = new DbMain.EFDbContext.ChatEntities())
         {
             var access = db.AccessTokens.FirstOrDefault(x => x.IsActive && x.Token == token);
             if (access == null)
             {
                 return(new OperationResult <UserExt>(null, false, "Faild authorization"));
             }
             curUser = access.User;
             if ((NetworkStatus)curUser.NetworkStatusId != NetworkStatus.Hidden)
             {
                 access.User.NetworkStatusId = (int)NetworkStatus.OnLine;
             }
             db.SaveChanges();
             UserRelationsMain.OnlineUsers.TryAdd(curUser.Login, this);
             UserRelationsMain.UserNetworkStatusChange(GetContacts(db, RelationStatus.Friendship), curUser.Login, NetworkStatus.OnLine);
             return(new OperationResult <UserExt>(new UserExt()
             {
                 BirthDate = curUser.Birthdate,
                 Icon = curUser.Icon,
                 Login = curUser.Login,
                 Name = curUser.Name,
                 NetworkStatus = (NetworkStatus)curUser.NetworkStatusId,
                 Phone = curUser.Phone
             }));
         }
     }
     catch (Exception ex)
     {
         return(new OperationResult <UserExt>(null, false, "Internal error. Try again later"));
     }
 }
示例#2
0
 private void CreateContactAndDialog(DbMain.EFDbContext.ChatEntities db, out DbMain.EFDbContext.Contact contact, DbMain.EFDbContext.User user, RelationStatus status)
 {
     contact = new DbMain.EFDbContext.Contact()
     {
         AdderId        = curUser.Id,
         InvitedId      = user.Id,
         RelationTypeId = (int)status
     };
     DbMain.EFDbContext.Conversation conversation = new DbMain.EFDbContext.Conversation()
     {
         AuthorId           = curUser.Id,
         PartnerId          = user.Id,
         Name               = $"Dialog: {curUser.Name} - {user.Name}",
         ConversationTypeId = (int)ConversationType.Dialog
     };
     contact.Conversation = conversation;
     DbMain.EFDbContext.ConversationMember member = new DbMain.EFDbContext.ConversationMember()
     {
         MemberId       = curUser.Id,
         Conversation   = conversation,
         MemberStatusId = (int)ConversationMemberStatus.Admin,
     };
     DbMain.EFDbContext.ConversationMember member2 = new DbMain.EFDbContext.ConversationMember()
     {
         MemberId       = user.Id,
         Conversation   = conversation,
         MemberStatusId = (int)(status != RelationStatus.BlockedByMe ? ConversationMemberStatus.Admin : ConversationMemberStatus.Blocked),
         AddedId        = curUser.Id
     };
     db.ConversationMembers.Add(member);
     db.ConversationMembers.Add(member2);
     db.Conversations.Add(conversation);
     db.Contacts.Add(contact);
 }