public ActionResult Create(CreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // Verify username isn't already taken
                    var user = context.Users.FirstOrDefault(u => u.Username == model.Username);
                    if (user != null)
                    {
                        throw new Exception("Username", new Exception("Username already taken"));
                    }

                    // Create new user and add to context
                    context.Users.Add(new User()
                    {
                        Username = model.Username
                    });

                    // Save changes to the database
                    context.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }

            return(View(model));
        }
        public ActionResult Create(CreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // Create new post and add to context
                    context.Posts.Add(new Post()
                    {
                        UserId = model.UserId,
                        Title  = model.Title
                    });

                    // Save changes to the database
                    context.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }

            model.UserOptions = context.Users.AsEnumerable();

            return(View(model));
        }
        public bool InsertUser(RegisterModel model)
        {
            using (dbContext = new UserManagerEntities())
            {
                User user;
                if (model.UserRole == UserType.SuperUser)
                {
                    user = new SuperUser();
                }
                else
                {
                    user = new UsualUser();
                }

                user.Email = model.Email;
                user.Login = model.Login;
                user.Password = model.Password;
                user.FirstName = model.FirstName;
                user.LastName = model.LastName;

                dbContext.Users.AddObject(user);
                dbContext.SaveChanges();
                return true;
            }
        }