// GET: Administration
        public ActionResult Index(string section = "users")
        {
            ViewBag.CurrentPage = "Admin";

            var viewmodel = new AdministrationViewModel {
                Users = new List <SiteUserModel>()
            };

            viewmodel.SectionName = section.ToLower();

            if (section == "users")
            {
                var usermanager = new AppUserManager(_userStore);

                foreach (var user in _userStore.Users.ToList())
                {
                    SiteUserModel siteuser = AutoMapper.Mapper.Map <SiteUserModel>(user);
                    siteuser.UserRoles = usermanager.GetRoles(user.Id).ToArray();
                    viewmodel.Users.Add(siteuser);
                }
            }
            else
            {
                viewmodel.SiteSettings = _acidRepos.GetSettings();
            }


            return(View(viewmodel));
        }
예제 #2
0
파일: UserService.cs 프로젝트: tczhd/SMLYS
        public Result RegisterUser(SiteUserModel siteUserModel)
        {
            var userContext = _userHandler.GetUserContext();
            var result      = new Result();

            if (userContext == null)
            {
                result.Message = "Session expired. ";
                return(result);
            }

            try
            {
                var doctor = new Doctor()
                {
                    Active         = true,
                    Age            = 1,
                    ClinicId       = userContext.ClinicId,
                    CreatedBy      = userContext.SiteUserId,
                    CreatedDateUtc = DateTime.UtcNow,
                    Email          = siteUserModel.Email,
                    FirstName      = siteUserModel.FirstName,
                    Gender         = 1,
                    LastName       = siteUserModel.LastName,
                    Title          = "Dr."
                };

                SiteUser siteUser = new SiteUser()
                {
                    FirstName       = siteUserModel.FirstName,
                    LastName        = siteUserModel.LastName,
                    Email           = siteUserModel.Email,
                    UserId          = siteUserModel.UserId,
                    SiteUserLevelId = siteUserModel.SiteUserLevelId,
                    Active          = true,
                    ClinicId        = userContext.ClinicId,
                    Doctor          = doctor
                };

                _siteUserRepository.Add(siteUser);

                result.Success = true;
                result.Message = "Create user success. ";
            }
            catch (Exception ex)
            {
                result.Message = "Add user failed: " + ex.Message;
            }

            return(result);
        }
예제 #3
0
        public async Task <IActionResult> RegisterUser(SiteUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var siteUserModel = new SiteUserModel {
                        Email           = model.Email,
                        FirstName       = model.FirstName,
                        IsDoctor        = true,
                        LastName        = model.LastName,
                        Password        = model.Password,
                        SiteUserId      = model.SiteUserId,
                        UserId          = user.Id,
                        SiteUserLevelId = 1
                    };

                    var registerUserResult = _userService.RegisterUser(siteUserModel);
                    if (registerUserResult.Success)
                    {
                        return(View(model));
                    }
                    else
                    {
                        await _userManager.DeleteAsync(user);

                        ModelState.AddModelError(siteUserModel.Email, "Create user Failed. ");
                    }
                }
                AddErrors(result);
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }