예제 #1
0
 public ActionResult EditUserRoles(string UserName)
 {
     //var roles = new string[] { "EW Coordinator", "EW-Experts" };
     //userService.AddRoleSample("Rahel", "Early Warning", roles);
     var model = new UserViewModel();
     model.UserName = UserName;
     List<Application> Applications = _userService.GetUserPermissions(UserName);
     ViewBag.hubs = new SelectList(_hubService.GetAllHub(), "HubID", "Name");
     model.Applications = Applications;
     return View(model);
 }
예제 #2
0
        public ActionResult New(UserViewModel userInfo)
        {
            //var messages = new List<string>();

            //// Check business rule and validations
            //if (userInfo.UserName == string.Empty)
            //    messages.Add("User name cannot be empty");
            //if (userInfo.FirstName == string.Empty)
            //    messages.Add("First name cannot be empty");
            //if (userInfo.LastName == string.Empty)
            //    messages.Add("Last Name cannot be empty");
            //if (userInfo.Password == string.Empty)
            //    messages.Add("Password cannot be empty");
            //if (userInfo.Password != userInfo.PasswordConfirm)
            //    messages.Add("Passwords do not match");

            //if (messages.Count > 0)
            //    return View();

            // If the supplied information is correct then persist it to the database
            var user = new UserProfile();

            user.UserName = userInfo.UserName;
            user.Password = _userService.HashPassword(userInfo.Password);

            // Set default values for required fields
            user.Disabled = false;
            user.LockedInInd = false;
            user.ActiveInd = true;
            user.NumberOfLogins = 0;

            //List<Cats.Models.Security.ViewModels.Application> app = userInfo.Applications;
            Dictionary<string, List<string>> roles = new Dictionary<string, List<string>>();
            //List<string> Roles;
            //foreach (var application in app)
            //{
            //    Roles = new List<string>();
            //    foreach (var role in application.Roles)
            //    {
            //        if (role.IsChecked)
            //            Roles.Add(role.RoleName);
            //    }
            //    if (Roles.Count > 0)
            //        roles.Add(application.ApplicationName, Roles);
            //}

            user.FirstName = userInfo.FirstName;
            user.LastName = userInfo.LastName;

            user.LanguageCode = "EN";
            user.Keyboard = "AM";
            user.PreferedWeightMeasurment = "MT";
            user.DatePreference = "GC";
            user.DefaultTheme = "Default";
            user.FailedAttempts = 0;
            user.LoggedInInd = false;

            if(_userService.Add(user, roles))
            {
                return View("Index");
            }

            return View();
        }
예제 #3
0
 public ActionResult New()
 {
     var model = new UserViewModel();
     //List<Cats.Models.Security.ViewModels.Application> Applications = userService.GetApplications("CATS");
     //model.Applications = Applications;
     return View(model);
 }
예제 #4
0
        public ActionResult EditUserRoles(UserViewModel userInfo)
        {
            var app = userInfo.Applications;
            var roles = new Dictionary<string, List<Role>>();
            var Roles = new List<Role>();

            //var user = _userService.FindBy(u=>u.UserName == userInfo.UserName).SingleOrDefault();

            var user = _userService.GetUserDetail(userInfo.UserName);
            user.DefaultHub = userInfo.DefaultHub;
            _userService.UpdateUser(user);

            foreach (var application in app)
            {
                foreach (var role in application.Roles)
                {
                    if (role.IsChecked)
                    {
                        _userService.AddRole(userInfo.UserName, application.ApplicationName, role.RoleName);
                    }
                    else if(!role.IsChecked)
                    {
                        //userService.RemoveRole(userInfo.UserName, application.ApplicationName, role.RoleName);
                    }
                }

                //if (Roles.Count > 0)
                //  roles.Add(application.ApplicationName, Roles);
            }

            return RedirectToAction("Index");
            //var user = new UserProfile();

            //var model = new UserViewModel();
            //model.UserName = userInfo.UserName;
            //List<Application> Applications = userService.GetUserPermissions(userInfo.UserName);

            //model.Applications = Applications;
            //return View(model);
        }
예제 #5
0
 public ActionResult New()
 {
     var model = new UserViewModel();
     init();
     //var caseteams = new List<CaseTeam>();
     //caseteams.Add(new CaseTeam() { ID = 1,CaseTeamName = "EarlyWarning"});
     //caseteams.Add(new CaseTeam() { ID = 2, CaseTeamName = "PSNP/FSCD" });
     //caseteams.Add(new CaseTeam() { ID = 3, CaseTeamName = "Logistics" });
     //caseteams.Add(new CaseTeam() { ID = 4, CaseTeamName = "Procurement" });
     //ViewBag.CaseTeams = caseteams;
     //ViewBag.Regions = _adminUnitService.GetRegions();
     return View(model);
 }
예제 #6
0
        public ActionResult EditUserRoles(UserViewModel userInfo)
        {
            var app = userInfo.Applications;
            var roles = new Dictionary<string, List<Role>>();
            var Roles = new List<Role>();

            //var user = _userService.FindBy(u=>u.UserName == userInfo.UserName).SingleOrDefault();
            List<Application> originalApps = _userService.GetUserPermissions(userInfo.UserName);
            var user = _userService.GetUserDetail(userInfo.UserName);
            //user.DefaultHub = userInfo.DefaultHub;
            _userService.UpdateUser(user);

            using (var e1 = app.GetEnumerator())
            using (var e2 = originalApps.GetEnumerator())
            {
                while (e1.MoveNext() && e2.MoveNext())
                {
                    var item1 = e1.Current;
                    var item2 = e2.Current;

                }
            }

            foreach (var application in app)
            {
                foreach (var role in application.Roles)
                {
                    if (role.IsChecked)
                    {
                        _userService.AddRole(userInfo.UserName, application.ApplicationName, role.RoleName);
                    }
                    else if(!role.IsChecked)
                    {
                        var isRoleAuthorized = false;
                        foreach(var originalApp in originalApps)
                        {
                            if (originalApp.ApplicationName == application.ApplicationName)
                            {
                                foreach (var originalRole in originalApp.Roles)
                                {
                                    if(originalRole.RoleName == role.RoleName)
                                    {
                                        if(originalRole.IsChecked)
                                        {
                                            isRoleAuthorized = true;
                                        }
                                    }
                                }
                            }
                        }
                        if (isRoleAuthorized)
                            _userService.RemoveRole(userInfo.UserName, application.ApplicationName, role.RoleName);
                    }
                }

                //if (Roles.Count > 0)
                //  roles.Add(application.ApplicationName, Roles);
            }

            return RedirectToAction("Index");
            //var user = new UserProfile();

            //var model = new UserViewModel();
            //model.UserName = userInfo.UserName;
            //List<Application> Applications = userService.GetUserPermissions(userInfo.UserName);

            //model.Applications = Applications;
            //return View(model);
        }