コード例 #1
0
        private void SyncUserManager(IActiveDirectoryContext adContext, Guid syncBatchGUID, User user, ManagerUser managerUser)
        {
            var managerUsers = _managerUserService.GetManagerUser(managerUser);

            if (managerUsers.Count() > 0)
            {
                var syncStatus = new SyncStatus
                {
                    ObjectGUID     = user.UserGuid,
                    ObjectName     = user.Username,
                    ObjectType     = "ManagerUser",
                    SyncBatchGUID  = syncBatchGUID,
                    SyncStatusText = "NOACTION",
                    ErrorMessage   = "Manager already exists"
                };
                _syncStatusService.Insert(syncStatus);
            }
            else
            {
                _managerUserService.Insert(managerUser);
                var syncStatus = new SyncStatus
                {
                    ObjectGUID     = user.UserGuid,
                    ObjectName     = user.Username,
                    ObjectType     = "ManagerUser",
                    SyncBatchGUID  = syncBatchGUID,
                    SyncStatusText = "INSERT"
                };
                _syncStatusService.Insert(syncStatus);
            }
            //TODO: If user has manager other than specified, may need to be deleted.
        }
コード例 #2
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            try
            {
                IEnumerable <ManagerUser> managerUsers = new List <ManagerUser>();
                List <string>             managerNames = new List <string>();
                var loggedUser = UserHelper.CurrentUserGuid(HttpContext);
                var user       = _userService.GetUserByUserGuid(loggedUser);

                var userViewModel = Models.ObjectMapper <User, UserViewModel> .Map(user);

                managerUsers = _managerUserService.GetManagerUser(loggedUser);

                foreach (var manager in managerUsers)
                {
                    var userManager = _userService.GetUserByUserGuid(manager.ManagerGUID);
                    var fullName    = Infrastructure.Helpers.FormatHelper.FormatFullName(userManager.Firstname, string.Empty, userManager.Lastname);
                    managerNames.Add(fullName);
                }

                userViewModel.Manager = string.Join(" , ", managerNames.OrderBy(x => x));

                return(View(userViewModel));
            }
            catch
            {
            }

            return(View());
        }
コード例 #3
0
        public ActionResult Edit(Guid id)
        {
            var userStatuses = _resourceAttributeValueService.GetResourceValuesByResourceType("User", "UserStatus");

            if (userStatuses != null && userStatuses.Count() > 0)
            {
                ViewBag.UserStatuses = userStatuses.Select(data => new SelectListItem {
                    Text = data.Name, Value = data.Value
                }).ToList();
            }
            var jobTitles = _resourceAttributeValueService.GetResourceValuesByResourceType("User", "JobTitle");

            if (jobTitles != null && jobTitles.Count() > 0)
            {
                ViewBag.JobTitles = jobTitles.Select(data => new SelectListItem {
                    Text = data.Name, Value = data.Value
                }).ToList();
            }
            var jobStatuses = _resourceAttributeValueService.GetResourceValuesByResourceType("User", "JobStatus");

            if (jobStatuses != null && jobStatuses.Count() > 0)
            {
                ViewBag.JobStatuses = jobStatuses.Select(data => new SelectListItem {
                    Text = data.Name, Value = data.Value
                }).ToList();
            }
            try
            {
                var user = _userService.GetUserByUserGuid(id);
                if (user != null)
                {
                    var managers = _managerUserService.GetManagerUser(user.UserGuid);
                    if (managers.Count() > 0)
                    {
                        Guid managerId = managers.FirstOrDefault().ManagerGUID;
                        var  manager   = _userService.GetUserByUserGuid(managerId);
                        if (manager != null)
                        {
                            user.Manager = manager.Firstname + " " + manager.Lastname;
                        }
                    }

                    var groups = _groupUserService.GetGroupUserByUserGUID(user.UserGuid);
                    if (groups.Count() > 0)
                    {
                        var groupId = groups.FirstOrDefault().GroupGUID;
                        var group   = _groupService.GetGroupByGUID(groupId);
                        if (group != null)
                        {
                            user.Group = group.CN;
                        }
                    }
                }
                var userViewModel = Mapper <User, UserEditViewModel> .Map(user);

                return(View(userViewModel));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(PartialView());
            }
        }