public ActionResult Edit(User userEdit)
 {
     User UserEdi = _ContextData.Get<User>(userEdit.Id);
     TryUpdateModel(UserEdi);
     _ContextData.SaveChanges( );
     return RedirectToAction("Sucess", "Home");
 }
 public ActionResult Delete(User userDelete)
 {
     User UserDel = _ContextData.Get<User>(userDelete.Id);
     _ContextData.Delete<User>(UserDel);
     _ContextData.SaveChanges( );
     return RedirectToAction("Sucess", "Home");
 }
        public ActionResult Create(User user)
        {
            user.DateRegister = DateTime.Now;

            user.Token = user.Name.GetHashCode( ).ToString( );
            user.Type = "Administrador";
            if (ModelState.IsValid)
            {

                MembershipCreateStatus createStatus;
                Membership.CreateUser(user.Name, user.Name.Trim( ) + "idezjobs", user.Email, null, null, true, null, out createStatus);
                if (createStatus == MembershipCreateStatus.Success)
                {
                    _ContextData.Add<User>(user);
                    _ContextData.SaveChanges( );

                    Roles.AddUserToRole(user.Name, user.Type);

                    return RedirectToAction("Sucess", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "Não foi possível criar o usuário");
                }
            }
            return View( );
        }
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                _ContextData.Add<User>(user);
                _ContextData.SaveChanges( );
                return RedirectToAction("Sucess", "Home");

            }
            return View( );
        }
        public IList<User> listaEmail( )
        {
            List<User> lista = new List<User>( );
            User usuario = new User( );
            usuario.Email = "*****@*****.**";
            usuario.DateRegister = new DateTime(1987, 07, 10);
            usuario.Name = "ademi";
            usuario.Type = "Admin";

            lista.Add(usuario);

            User usuario1 = new User( );

            usuario1.Email = "*****@*****.**";
            usuario1.DateRegister = new DateTime(1988, 08, 10);
            usuario1.Name = "joao";
            usuario1.Type = "Teste";

            lista.Add(usuario1);

            User usuario2 = new User( );

            usuario2.Email = "*****@*****.**";
            usuario2.DateRegister = new DateTime(1988, 08, 10);
            usuario2.Name = "paty";
            usuario2.Type = "Teste";

            lista.Add(usuario2);

            User usuario3 = new User( );

            usuario3.Email = "*****@*****.**";
            usuario3.DateRegister = new DateTime(1988, 08, 10);
            usuario3.Name = "Ok Ok";
            usuario3.Type = "Teste";

            lista.Add(usuario3);

            return lista.ToList( );
        }
        protected void Application_Start( )
        {
            AreaRegistration.RegisterAllAreas( );

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            if (System.Web.Security.Roles.GetAllRoles( ).Length == 0)
            {
                using (IContextData ctx = new ContextDataNH( ))
                {
                    ctx.setup( );
                    System.Web.Security.Roles.CreateRole("Administrador");
                    System.Web.Security.Roles.CreateRole("Company");
                    System.Web.Security.Roles.CreateRole("Student");

                    MembershipCreateStatus status;
                    Membership.CreateUser("IdezJobs", "JobsIdezypa", "*****@*****.**", null, null, true, out status);
                    Membership.CreateUser("Estudante", "senha123", "*****@*****.**", null, null, true, out status);
                    Membership.CreateUser("Empresa", "empresa123", "*****@*****.**", null, null, true, out status);
                    if (status == MembershipCreateStatus.Success)
                    {
                        Administrator Administ = new Administrator( );
                        Administ.Name = "IdezJobs";
                        Administ.Password = "******";
                        Administ.Email = "*****@*****.**";
                        Administ.Type = "Administrator";

                        ctx.Add<Administrator>(Administ);
                        ctx.SaveChanges( );

                        User userEstudante = new User( );
                        userEstudante.DateRegister = DateTime.Now;
                        userEstudante.Email = "*****@*****.**";
                        userEstudante.Name = "Estudante";
                        userEstudante.Token = "Token";
                        userEstudante.Type = "Estudante";

                        ctx.Add<User>(userEstudante);
                        ctx.SaveChanges( );

                        User userEmpresa = new User( );
                        userEmpresa.DateRegister = DateTime.Now;
                        userEmpresa.Email = "*****@*****.**";
                        userEmpresa.Name = "Empresa";
                        userEmpresa.Token = "Token Empresa";
                        userEmpresa.Type = "Company";

                        ctx.Add<User>(userEmpresa);
                        ctx.SaveChanges( );

                        Status s1 = new Status( );
                        s1.Description = "Aberto";
                        ctx.Add<Status>(s1);
                        ctx.SaveChanges( );

                        Status s2 = new Status( );
                        s2.Description = "Fechado";
                        ctx.Add<Status>(s2);
                        ctx.SaveChanges( );

                        Roles.AddUserToRole("IdezJobs", "Administrador");
                        Roles.AddUserToRole("Estudante", "Student");
                        Roles.AddUserToRole("Empresa", "Company");

                        ctx.Dispose( );
                    }
                }
            }
        }