예제 #1
0
 //Delete User
 public void DeleteUser(string userName, string password)
 {
     if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
     {
         User user = GetUser(userName, password);
         if (user != null)
         {
             using (ChatDbContext context = new ChatDbContext())
             {
                 try
                 {
                     context.Users.Remove(user);
                     context.SaveChanges();
                 }
                 catch (Exception ex)
                 {
                     throw new Exception("En Error during removing the user", ex.InnerException);
                 }
             }
         }
     }
 }
예제 #2
0
 //Add New User to DB
 public void AddUser(User user)
 {
     if (user != null)
     {
         using (ChatDbContext context = new ChatDbContext())
         {
             try
             {
                 user.UserId = context.Users.Count();
                 context.Users.Add(user);
                 context.SaveChanges();
             }
             catch (Exception ex)
             {
                 throw new Exception("En Error during registration", ex);
             }
         }
     }
     else
     {
         throw new Exception("The user object is null");
     }
 }
예제 #3
0
 //Get All Message from selected user
 public ICollection <Message> GetMessagePerUser(User user)
 {
     if (user != null)
     {
         List <Message> messages = new List <Message>();
         using (ChatDbContext context = new ChatDbContext())
         {
             try
             {
                 messages = context.Messages.Where(m => m.UserName == user.UserName).ToList();
                 return(messages);
             }
             catch (Exception ex)
             {
                 throw new Exception("En Error during registration", ex);
             }
         }
     }
     else
     {
         throw new Exception("The user object is null");
     }
 }