public ActionResult Edit(string name, FormCollection collection)
        {
            try
            {
                var userId = User.Identity.GetUserName();
                if (userRolesRepository.GetRoleByUserName(userId) != null && userRolesRepository.GetRoleByUserName(userId).IdUserType == "Admin")
                {
                    // TODO: Add update logic here

                    UsersClustersModel usersModel = new UsersClustersModel();
                    usersModel.Name          = Request.Form["UserName"];
                    usersModel.IdDepartment  = Request.Form["Department"];
                    usersModel.IdUserType    = Request.Form["UserType"];
                    usersModel.Id            = Guid.NewGuid().ToString();
                    usersModel.Discriminator = "";
                    UpdateModel(usersModel);

                    userRolesRepository.UpdateUserRole(usersModel);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Contact", "Home"));
                }
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 2
0
 public bool IsDuplicateUserName(UsersClustersModel userRole)
 {
     if (GetRoleByUserName(userRole.Name) == null)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
        public ActionResult Details(string Id)
        {
            var userId = User.Identity.GetUserName();

            if (userRolesRepository.GetRoleByUserName(userId) != null && userRolesRepository.GetRoleByUserName(userId).IdUserType == "Admin")
            {
                UsersClustersModel UserRolesModel = userRolesRepository.GetRoleById(Id);
                return(View("DetailsUserRoles", UserRolesModel));
            }
            else
            {
                return(RedirectToAction("Contact", "Home"));
            }
        }
Exemplo n.º 4
0
        public void UpdateUserRole(UsersClustersModel userRole)
        {
            AspNetRole userRoleDb = dbContext.AspNetRoles.FirstOrDefault(x => x.Id == userRole.Id);

            if (userRoleDb != null)
            {
                userRoleDb.Name          = userRole.Name;
                userRoleDb.IdDepartment  = userRole.IdDepartment;
                userRoleDb.IdUserType    = userRole.IdUserType;
                userRoleDb.Id            = userRole.Id;
                userRoleDb.Discriminator = userRole.Discriminator;
                dbContext.SubmitChanges();
            }
        }
Exemplo n.º 5
0
        private AspNetRole MapModelToDbObject(UsersClustersModel role)
        {
            AspNetRole roleDb = new AspNetRole();

            if (role != null)
            {
                roleDb.Id            = role.Id;
                roleDb.Name          = role.Name;
                roleDb.IdDepartment  = role.IdDepartment;
                roleDb.IdUserType    = role.IdUserType;
                roleDb.Discriminator = role.Discriminator;
                return(roleDb);
            }

            return(null);
        }
Exemplo n.º 6
0
        private UsersClustersModel MapDbObjectToModel(AspNetRole dbRole)
        {
            UsersClustersModel role = new UsersClustersModel();

            if (dbRole != null)
            {
                role.Name          = dbRole.Name;
                role.IdDepartment  = dbRole.IdDepartment;
                role.IdUserType    = dbRole.IdUserType;
                role.Id            = dbRole.Id;
                role.Discriminator = dbRole.Discriminator;

                return(role);
            }

            return(null);
        }
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                var userId = User.Identity.GetUserName();
                if (userRolesRepository.GetRoleByUserName(userId) != null && userRolesRepository.GetRoleByUserName(userId).IdUserType == "Admin")
                {
                    UsersClustersModel usersModel = new UsersClustersModel();

                    usersModel.Name          = Request.Form["UserName"];
                    usersModel.IdDepartment  = Request.Form["Department"];
                    usersModel.IdUserType    = Request.Form["UserType"];
                    usersModel.Id            = Guid.NewGuid().ToString();
                    usersModel.Discriminator = "";

                    UpdateModel(usersModel);


                    if (userRolesRepository.IsDuplicateUserName(usersModel) == false)
                    {
                        userRolesRepository.InsertUserRole(usersModel);

                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        return(RedirectToAction("IndexError"));
                    }
                }
                else
                {
                    return(RedirectToAction("Contact", "Home"));
                }
            }
            catch (Exception e)
            {
                ViewBag.Message_Delete = String.Format(e.Message);
                return(View("CreateUserRolesAssignment"));
            }
        }
Exemplo n.º 8
0
 public void InsertUserRole(UsersClustersModel userRole)
 {
     dbContext.AspNetRoles.InsertOnSubmit(MapModelToDbObject(userRole));
     dbContext.SubmitChanges();
 }