Exemple #1
0
        public ActionResult AddNew(UserEdit userEdit)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (userEdit.Password.Trim().Equals(userEdit.PasswordRepeat.Trim()))
                    {
                        using (Models.DataAccess.db_AdminErickEntities db = new Models.DataAccess.db_AdminErickEntities())
                        {
                            Users users = new Users();
                            users.IdMembership = int.Parse(userEdit.IdMembership.ToString());
                            users.IdRole       = int.Parse(userEdit.IdRol.ToString());
                            users.Password     = userEdit.Password.Trim();
                            users.UserName     = userEdit.UserName.Trim();

                            db.Users.Add(users);
                            db.SaveChanges();

                            return(Redirect("~/Users/Success/"));
                        }
                    }
                    ViewBag.ErrorPass = "******";
                }
                userEdit.RolSelected        = GetRoles();
                userEdit.MembershipSelected = GetMemberships();
                return(View(userEdit));
            }
            catch (Exception e)
            {
                return(Redirect("~/Error/"));
            }
        }
Exemple #2
0
 private List <MembershipEdit> GetMemberships()
 {
     using (Models.DataAccess.db_AdminErickEntities db = new Models.DataAccess.db_AdminErickEntities())
     {
         return((from member in db.Memberships
                 select new MembershipEdit
         {
             Id = member.Id,
             MembershipName = member.MembershipName
         }).ToList());
     }
 }
Exemple #3
0
 private List <RolesEdit> GetRoles()
 {
     using (Models.DataAccess.db_AdminErickEntities db = new Models.DataAccess.db_AdminErickEntities())
     {
         return((from roles in db.Roles
                 select new RolesEdit
         {
             Id = roles.Id,
             RoleName = roles.RoleName
         }).ToList());
     }
 }