Example #1
0
        public ActionResult View(int id)
        {
            _entities = new MvcForumsEntities();

            Forum requestedForum = _entities.Forum.Include("Thread").Single(forum => forum.id == id);
            requestedForum.Thread.Load();

            return View(requestedForum);
        }
Example #2
0
        public ActionResult Index()
        {
            _entities = new MvcForumsEntities();

            var tempForums = (from forum in _entities.Forum select forum);

            _entities = null;
            return View(tempForums.Select(forum => forum).ToList<Forum>());
        }
Example #3
0
        public ActionResult Forums(ForumViewModel newForum)
        {
            if (!ModelState.IsValid)
                return View();

            try
            {
                MvcForumsEntities entities;
                using (entities = new MvcForumsEntities())
                {
                    Forum forum = new Forum() { description = newForum.Description, name = newForum.Name };
                    entities.AddToForum(forum);
                    entities.SaveChanges();
                }

            }
            catch (Exception e)
            {

            }

            return View();
        }
        public override bool ValidateUser(string username, string password)
        {
            if(string.IsNullOrEmpty(password.Trim())) return false;

            string hash = EncryptPassword(password);

            MvcForumsEntities forumEntities = new MvcForumsEntities();
            User user = forumEntities.User.Single(dbUser => dbUser.UserName == username);
            if (user == null) return false;

            if (user.Password == password)
            {
                User = user;
                return true;
            }

            return false;
        }
        public User CreateUser(string userName ,string password, string email)
        {
            using (MvcForumsEntities forumEntities = new MvcForumsEntities())
            {
                //Checking if a user with the given name exists..if not create, otherwise return null
                if(forumEntities.User.Where(user => user.UserName == userName).Count() == 0)
                {
                    User newUser = new User(){UserName = userName, Password = password, EmailAddress=email, CreateDate=DateTime.Now};
                    forumEntities.AddToUser(newUser);
                    try
                    {
                        forumEntities.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        return null;
                    }
                    return newUser;
                }
                else
                    return null;

            }
        }
Example #6
0
 public AdminRoleProvider()
 {
     _repository = new MvcForumsEntities();
 }
        public override bool ValidateUser(string username, string password)
        {
            if(string.IsNullOrEmpty(password.Trim())) return false;

            string hash = EncryptPassword(password);

            MvcForumsEntities forumEntities = new MvcForumsEntities();
            User user = (User)from users in forumEntities.Users where Name == username select users;
            if (user == null) return false;

            if (user.Password == password)
            {
                User = user;
                return true;
            }

            return false;
        }
        public User CreateUser(string userName ,string password, string email)
        {
            using (MvcForumsEntities forumEntities = new MvcForumsEntities())
            {
                //Checking if a user with the given name exists..if not create, otherwise return null
                if(forumEntities.Users.Where(user => user.UserName == userName).Count() == 0)
                {
                    User newUser = new User(){UserName = userName, Password = password};
                    forumEntities.AddToUsers(newUser);
                    return newUser;
                }
                else
                    return null;

            }
        }