コード例 #1
0
 public static void RegisterUser(string username, string password, string RetryPassword,
                                 string FirstName, string LastName)
 {
     using (var context = new BlogDbEntities())
     {
         if (HasUserName(username))
         {
             throw new UserAlreadyExistsException();
         }
         else if (password == RetryPassword)
         {
             User NewUser = new User();
             NewUser.UserName   = username;
             NewUser.Password   = password;
             NewUser.FirstName  = FirstName;
             NewUser.LastName   = LastName;
             NewUser.Created_At = DateTime.Now;
             context.User.Add(NewUser);
             context.SaveChanges();
         }
         else
         {
             throw new PasswordsNotEqualException();
         }
     }
 }
コード例 #2
0
 public static bool HasUserName(string username)
 {
     using (var context = new BlogDbEntities())
     {
         var hasuser = context.User.Any(u => u.UserName.ToLower() == username.ToLower());
         return(hasuser);
     }
 }
コード例 #3
0
 public static void DeletePost(int id)
 {
     using (var context = new BlogDbEntities())
     {
         Post deleteThis = context.Post.Find(id);
         context.Post.Remove(deleteThis);
         context.SaveChanges();
     }
 }
コード例 #4
0
 public static void ModifyPost(int id, string body)
 {
     using (var context = new BlogDbEntities())
     {
         Post modifyThis = context.Post.Find(id);
         modifyThis.Body                 = body;
         modifyThis.Modified_At          = DateTime.Now;
         context.Entry(modifyThis).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #5
0
 public static void UserLogout()
 {
     using (var context = new BlogDbEntities())
     {
         var CurrentUser = context.User.Find(UIRepository.Instance.CurrentClientId);
         CurrentUser.Last_Login           = DateTime.Now;
         context.Entry(CurrentUser).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
     UIRepository.Instance.CurrentClientId = 0;
 }
コード例 #6
0
 public static void AddPost(string body, int user_id)
 {
     using (var context = new BlogDbEntities())
     {
         Post newPost = new Post();
         newPost.Body       = body;
         newPost.User_Id    = user_id;
         newPost.Created_At = DateTime.Now;
         context.Post.Add(newPost);
         context.SaveChanges();
     }
 }
コード例 #7
0
 public static bool UserLogin(string username, string password)
 {
     using (var context = new BlogDbEntities()) // db kapcsolat
     {
         var hasUser = context.User.Any(user => user.UserName.ToLower() == username.ToLower());
         if (!hasUser)
         {
             throw new UserNotFoundException();
         }
         else
         {
             var user = context.User.Where(u => u.UserName.ToLower() == username.ToLower()).First();
             if (user.Password != password)
             {
                 throw new NotCorrectPasswordException();
             }
             else
             {
                 UIRepository.Instance.CurrentClientId = user.Id;
                 return(true);
             }
         }
     }
 }