Example #1
0
        // GET: AppAccount/Delete/5
        public ActionResult Delete(string id)
        {
            var user    = _userManager.Users.First(u => u.Id == id);
            var adapter = new UserAdapterModel(user);

            return(View(adapter));
        }
Example #2
0
        // GET: AppAccount/Edit/5
        public ActionResult Edit(string id)
        {
            var user    = _userManager.Users.FirstOrDefault(u => u.Id == id);
            var adapter = new UserAdapterModel(user);

            return(View(user));
        }
Example #3
0
        public async Task <ActionResult> Create(UserAdapterModel adapter)
        {
            if (!ModelState.IsValid)
            {
                return(View(adapter));
            }

            if (adapter.Password1 != adapter.Password2)
            {
                ModelState.AddModelError("", "Passwords do not match.");
                return(View(adapter));
            }

            var result = await _userManager.CreateAsync(adapter._identityUser, adapter.Password1);

            if (!result.Succeeded)
            {
                return(View(adapter));
            }

            var roles = JsonConvert.DeserializeObject <string[]>(adapter.Roles);

            foreach (var r in roles)
            {
                var actualUser = _userManager.Users.FirstOrDefault(u => u.UserName == adapter._identityUser.UserName);
                result = await _userManager.AddToRoleAsync(actualUser, r);
            }
            return(RedirectToAction(nameof(Index)));
        }
Example #4
0
        // GET: AppAccount/Create
        public ActionResult Create()
        {
            var adapter = new UserAdapterModel(new AppIdentityUser());

            adapter.Departments     = _departmentRepository.GetAll().ToList();
            adapter.Buildings       = _buildingRepository.GetAll().ToList();
            adapter.TechnicalGroups = _technicalGroupRepository.GetAll().ToList();
            return(View(adapter));
        }
Example #5
0
        public async Task <ActionResult> Edit(UserAdapterModel createUserViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(createUserViewModel));
            }

            await _userManager.UpdateAsync(createUserViewModel._identityUser);

            return(RedirectToAction(nameof(Index)));
        }
Example #6
0
        // GET: AppAccount/Details/5
        public ActionResult Details(string id)
        {
            var user    = _userManager.Users.FirstOrDefault(u => u.Id == id);
            var adapter = new UserAdapterModel(user);

            if (user.DepartmentId.HasValue)
            {
                adapter.Departments = new List <DepartmentModel> {
                    _departmentRepository.GetById(user.DepartmentId.Value)
                }
            }
            ;

            if (user.OfficeBuildingId.HasValue)
            {
                adapter.Buildings = new List <Building> {
                    _buildingRepository.GetById(user.OfficeBuildingId.Value)
                };
                if (user.OfficeRoomId.HasValue)
                {
                    adapter.Rooms = new List <Room> {
                        _roomRepository.GetById(user.OfficeRoomId.Value)
                    }
                }
                ;
            }
            if (user.TechnicalGroupId.HasValue)
            {
                adapter.TechnicalGroups = new List <TechnicalGroup> {
                    _technicalGroupRepository.GetById(user.TechnicalGroupId.Value)
                };
                if (user.SubTechnicalGroupId.HasValue)
                {
                    adapter.SubTechnicalGroups = new List <SubTechnicalGroup> {
                        _subTechnicalGroupRepository.GetById(user.SubTechnicalGroupId.Value)
                    }
                }
                ;
            }

            return(View(adapter));
        }