public override async Task <IdentityResult> AddToRoleAsync(string userId, string role)
        {
            var identityResult = await base.AddToRoleAsync(userId, role);

            _permissionsCache.TryRemoveEntry(userId);
            return(identityResult);
        }
        public async Task <HttpResponseMessage> PutJobInfo(ApplicationUserPutJobInfoViewModel model)
        {
            var userOrg = GetUserAndOrganization();
            var editorIsAdministrator = await _permissionService.UserHasPermissionAsync(userOrg, AdministrationPermissions.ApplicationUser);

            if (editorIsAdministrator && !model.EmploymentDate.HasValue)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            if (!(editorIsAdministrator || model.Id == User.Identity.GetUserId()))
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden));
            }

            var validatedModelInfo = await ValidateModelInfoAsync(model);

            if (!validatedModelInfo.IsSuccessStatusCode)
            {
                return(validatedModelInfo);
            }

            var applicationUser = await _applicationUserRepository.Get(u => u.Id == model.Id, includeProperties : "Roles,Projects,Skills,WorkingHours").FirstOrDefaultAsync();

            if (!editorIsAdministrator)
            {
                model.EmploymentDate = applicationUser?.EmploymentDate;
            }

            if (applicationUser == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Resources.Common.DoesNotExist, Resources.Models.ApplicationUser.ApplicationUser.EntityName)));
            }

            _mapper.Map(model, applicationUser);

            applicationUser.Skills = await _skillsRepository.Get(s => model.SkillIds.Contains(s.Id)).ToListAsync();

            if (editorIsAdministrator && model.RoleIds != null)
            {
                await UpdateRolesAsync(applicationUser, model.RoleIds);
            }

            if (applicationUser.WorkingHours?.OrganizationId == 0)
            {
                applicationUser.WorkingHours.OrganizationId = GetUserAndOrganization().OrganizationId;
            }

            await _projectService.AddProjectsToUserAsync(applicationUser.Id, model.ProjectIds, userOrg);

            await _unitOfWork.SaveAsync();

            _permissionsCache.TryRemoveEntry(applicationUser.Id);

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Beispiel #3
0
 public void RemoveCache(string userId)
 {
     _permissionsCache.TryRemoveEntry(userId);
 }