Ejemplo n.º 1
0
 public AppUser FromAppUserEditVM(AppUserEditVM model, AppUser user)
 {
     user.FirstName = model.FirstName;
     user.LastName  = model.LastName;
     user.IsActive  = model.IsActive;
     user.Login     = model.Login;
     return(user);
 }
Ejemplo n.º 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);
        }