Exemple #1
0
        public ActionResult Create(UserProfile userprofile)
        {
            if (ModelState.IsValid)
            {
                db.UserProfiles.Add(userprofile);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(userprofile);
        }
Exemple #2
0
        private void UpdateUserRoles(UserProfile user)
        {
            var roles = (SimpleRoleProvider)Roles.Provider;
            if (user.Administrator == true)
            {
                if (!roles.GetRolesForUser(user.UserName).Contains("Administrator"))
                {
                    roles.AddUsersToRoles(new[] { user.UserName }, new[] { "Administrator" });
                }
            }
            else
            {
                if (roles.GetRolesForUser(user.UserName).Contains("Administrator"))
                {
                    roles.RemoveUsersFromRoles(new[] { user.UserName }, new[] { "Administrator" });
                }
            }

            if (user.Coordinator == true)
            {
                if (!roles.GetRolesForUser(user.UserName).Contains("Coordinator"))
                {
                    roles.AddUsersToRoles(new[] { user.UserName }, new[] { "Coordinator" });
                }
            }
            else
            {
                if (roles.GetRolesForUser(user.UserName).Contains("Coordinator"))
                {
                    roles.RemoveUsersFromRoles(new[] { user.UserName }, new[] { "Coordinator" });
                }
            }
        }
Exemple #3
0
        public ActionResult UpdateUserProfile(UserProfile model)
        {
            UserProfile target = db.UserProfiles.Find(WebSecurity.CurrentUserId);
            target.FullName = model.FullName;
            target.Phone = model.Phone;
            target.Email = model.Email;
            target.Administrator = model.Administrator;
            target.Coordinator = model.Coordinator;
            db.Entry(target).State = System.Data.EntityState.Modified;
            db.SaveChanges();

               // return View(model);
            return RedirectToAction("Manage", new { Message = ManageMessageId.UpdateProfileSuccess });
        }