예제 #1
0
        public static int RegisterNewUser(RegisterModel model)
        {
            using (BlogDbContext db = new BlogDbContext())
            {
                if (db.Users.ToList().Count != 0)
                {
                    //Check if user exist
                    if (db.Users.Any(u => u.Username.Equals(model.Login)))
                    {
                        return((int)Registration.UserExists);
                    }
                }

                User newUser = new User
                {
                    Username  = model.Login,
                    Password  = GetMethods.GetHash(model.Password),
                    Name      = model.Name,
                    Surname   = model.Surname,
                    Email     = model.Email,
                    RoleId    = 1,
                    IsDeleted = false
                };
                db.Users.Add(newUser);
                db.SaveChanges();
                return((int)Registration.Success);
            }
        }
예제 #2
0
 public static bool IsUsersPost(int postid, string username)
 {
     using (BlogDbContext db = new BlogDbContext())
     {
         int userId = GetMethods.GetUserId(username);
         if (db.Posts.Any(p => p.PostId == postid && p.UserId == userId))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #3
0
 public static void AddNewPost(PostModel post, string login)
 {
     using (BlogDbContext db = new BlogDbContext())
     {
         var newPost = new Post
         {
             Title   = post.Title,
             Slug    = GetMethods.GetSlug(post.Title),
             Content = post.Content,
             UserId  = db.Users.Where(u => u.Username.Equals(login)).Select(u => u.UserId)
                       .FirstOrDefault(),
             PublishDate = DateTime.Now,
             IsDeleted   = false
         };
         db.Posts.Add(newPost);
         db.SaveChanges();
     }
 }