Пример #1
0
        public AppUserDetailsVM GetAppUserDetailsVM(int userId)
        {
            AppUser          crmUser = AppUserRepository.GetSingle(x => x.Id == userId);
            AppUserDetailsVM result  = AppUserConverter.ToAppUserDetailsVM(crmUser);

            return(result);
        }
Пример #2
0
        public void Edit(AppUserEditVM model)
        {
            AppUser appUser = AppUserRepository.GetSingle(x => x.Id == model.Id);

            if (appUser == null)
            {
                throw new BussinesException(1001, ErrorResource.NoData);
            }
            appUser = AppUserConverter.FromAppUserEditVM(model, appUser);
            AppUserRepository.Edit(appUser);


            AppRole appRole = AppRoleRepository.GetSingle(x => x.AppRoleType == model.Role);

            if (appRole == null)
            {
                if (model.Role == AppRoleType.Administrator)
                {
                    appRole = AppRoleService.AddRole(AppRoleType.Administrator, "Administratorzy", "Grupa administratorów systemu");
                }
            }
            AppUserRole appUserRole = AppUserRoleRepository.GetSingle(x => x.AppUserId == model.Id);

            if (appUserRole == null)
            {
                appUserRole = new AppUserRole()
                {
                    AppRoleId = appRole.Id,
                    AppUserId = appUser.Id
                };
                AppUserRoleRepository.Add(appUserRole);
                AppUserRoleRepository.Save();
            }
            appUserRole = AppUserRoleConverter.FromAppUserEditVM(appUserRole, appRole);
            AppUserRoleRepository.Edit(appUserRole);
        }