Exemple #1
0
 public bool InsertRoom(string name, ChatRoomType chatRoomType = ChatRoomType.Public)
 {
     try
     {
         using (var dbContext = new AsanaDbContext())
         {
             ChatRoom chat = new ChatRoom()
             {
                 Name = name, ProjectId = CurrentProject.Instance.Project.Id, ChatRoomType = chatRoomType, Desc = "Don't have description."
             };
             dbContext.ChatRooms.Add(chat);
             dbContext.ChatRoomUsers.Add(new ChatRoomUsers()
             {
                 UserId = CurrentUser.Instance.User.Id, ChatRoomId = chat.ID
             });
             dbContext.SaveChanges();
         }
         return(true);
     }
     catch (Exception err)
     {
         Log.Error(err.Message);
         return(false);
     }
 }
Exemple #2
0
 public bool InsertDirectMessage(string email, ChatRoomType chatRoomType = ChatRoomType.Direct)
 {
     try
     {
         using (var dbContext = new AsanaDbContext())
         {
             var friendUser = dbContext.Users.SingleOrDefault(x => x.Email == email);
             if (friendUser == null || dbContext.ChatRooms.Any(x => x.Name == email + " - " + CurrentUser.Instance.User.Email) || !dbContext.Projects.Any(x => x.UserId == friendUser.Id && x.Id == CurrentProject.Instance.Project.Id))
             {
                 throw new Exception();
             }
             ChatRoom chat = new ChatRoom()
             {
                 Name = email + " - " + CurrentUser.Instance.User.Email, ProjectId = CurrentProject.Instance.Project.Id, ChatRoomType = chatRoomType, Desc = "Don't have description."
             };
             dbContext.ChatRooms.Add(chat);
             dbContext.ChatRoomUsers.Add(new ChatRoomUsers()
             {
                 UserId = CurrentUser.Instance.User.Id, ChatRoomId = chat.ID
             });
             dbContext.ChatRoomUsers.Add(new ChatRoomUsers()
             {
                 UserId = friendUser.Id, ChatRoomId = chat.ID
             });
             dbContext.SaveChanges();
         }
         return(true);
     }
     catch (Exception err)
     {
         Errors.SeacrhFriendErrorMsg();
         return(false);
     }
 }
Exemple #3
0
 public void MarkedAllMail()
 {
     try
     {
         using (var db = new AsanaDbContext())
         {
             db.Mails.Where(x => x.UserId == CurrentUser.Instance.User.Id).ToList().ForEach(x => x.Marked = true);
             db.SaveChanges();
         }
     }
     catch (Exception err)
     {
         Log.Error(err.Message);
     }
 }
Exemple #4
0
 public void RemoveStarred(Guid id)
 {
     try
     {
         using (var db = new AsanaDbContext())
         {
             db.Mails.Single(x => x.ID == id).Favorite = false;
             db.SaveChanges();
         }
     }
     catch (Exception err)
     {
         Log.Error(err.Message);
     }
 }
Exemple #5
0
 public void SetMarked(Guid id)
 {
     try
     {
         using (var db = new AsanaDbContext())
         {
             db.Mails.Single(x => x.ID == id).Marked = true;
             db.SaveChanges();
         }
     }
     catch (Exception err)
     {
         Log.Error(err.Message);
     }
 }
Exemple #6
0
 public bool ForgotControl(string NewPassword)
 {
     try
     {
         using (var db = new AsanaDbContext())
         {
             string email = CurrentUser.Instance.User.Email;
             db.Users.Single(users => users.Email == email).Password = PasswordHasher.Hash(NewPassword);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception error)
     {
         Log.Error(error.Message);
         return(false);
     }
 }
Exemple #7
0
 public bool SendMessagesChannel(Guid ChatRoomId, string body)
 {
     try
     {
         using (var db = new AsanaDbContext())
         {
             db.Messages.Add(new Message()
             {
                 Body = body, ChatRoomId = ChatRoomId, SendTime = DateTime.Now, UserId = CurrentUser.Instance.User.Id
             });
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception err)
     {
         Log.Error(err.Message);
         return(false);
     }
 }
Exemple #8
0
 public bool JoinRoom(Guid ChatId)
 {
     try
     {
         using (var dbContext = new AsanaDbContext())
         {
             //int ChatId = db.ChatRooms.Single(x => x.Name == name).ID;
             dbContext.ChatRoomUsers.Add(new ChatRoomUsers()
             {
                 ChatRoomId = ChatId, UserId = CurrentUser.Instance.User.Id
             });
             dbContext.SaveChanges();
         }
         return(true);
     }
     catch (Exception err)
     {
         Log.Error(err.Message);
         return(false);
     }
 }
Exemple #9
0
        public bool RemoveRoom(string name)
        {
            try
            {
                using (var dbContext = new AsanaDbContext())
                {
                    Guid ChatId = dbContext.ChatRooms.SingleOrDefault(x => x.Name == name && x.ProjectId == CurrentProject.Instance.Project.Id).ID;

                    dbContext.ChatRoomUsers.Add(new ChatRoomUsers()
                    {
                        ChatRoomId = ChatId, UserId = CurrentUser.Instance.User.Id
                    });
                    dbContext.SaveChanges();
                    return(true);
                }
            }
            catch (Exception err)
            {
                Log.Error(err.Message);
                return(false);
            }
        }