public async Task <IActionResult> AddPlastDegreeForUser(UserPlastDegreePostDTO userPlastDegreePostDTO) { if (!await HasAccessAsync(userPlastDegreePostDTO.UserId)) { return(StatusCode(StatusCodes.Status403Forbidden)); } if (await _plastDegreeService.AddPlastDegreeForUserAsync(userPlastDegreePostDTO) && (((await _userManager.GetRolesAsync(await _userManager.GetUserAsync(User))).Contains(Roles.CityHead) && new List <int>() { 1, 7 }.Contains(userPlastDegreePostDTO.PlastDegreeId)) || !(await _userManager.GetRolesAsync(await _userManager.GetUserAsync(User))).Contains(Roles.CityHead))) { return(Created("GetAllDegrees", userPlastDegreePostDTO.PlastDegreeId)); } if (await _plastDegreeService.AddPlastDegreeForUserAsync(userPlastDegreePostDTO) && (((await _userManager.GetRolesAsync(await _userManager.GetUserAsync(User))).Contains(Roles.CityHeadDeputy) && new List <int>() { 1, 7 }.Contains(userPlastDegreePostDTO.PlastDegreeId)) || !(await _userManager.GetRolesAsync(await _userManager.GetUserAsync(User))).Contains(Roles.CityHeadDeputy))) { return(Created("GetAllDegrees", userPlastDegreePostDTO.PlastDegreeId)); } return(BadRequest()); }
/// <inheritdoc /> public async Task <bool> AddPlastDegreeForUserAsync(UserPlastDegreePostDTO userPlastDegreePostDTO) { bool isAdded = false; var userDto = await _userManagerService.FindByIdAsync(userPlastDegreePostDTO.UserId); if (userDto != null) { List <UserPlastDegree> userPlastDegrees = _mapper.Map <IEnumerable <UserPlastDegree> >(userDto.UserPlastDegrees).ToList(); if (!userPlastDegrees.Any(upd => upd.PlastDegree.Id == userPlastDegreePostDTO.PlastDegreeId)) { UserPlastDegree userPlastDegree = _mapper.Map <UserPlastDegree>(userPlastDegreePostDTO); PlastDegree plastDegree = await _repoWrapper.PlastDegrees.GetFirstOrDefaultAsync(pd => pd.Id == userPlastDegreePostDTO.PlastDegreeId); if (plastDegree != null) { userPlastDegree.PlastDegree = plastDegree; await SetDegreeAsCurrent(userPlastDegree.IsCurrent); _repoWrapper.UserPlastDegrees.Attach(userPlastDegree); _repoWrapper.UserPlastDegrees.Create(userPlastDegree); await _repoWrapper.SaveAsync(); isAdded = true; } } } return(isAdded); }
public async Task <IActionResult> AddPlastDegreeForUser(UserPlastDegreePostDTO userPlastDegreePostDTO) { if (await _plastDegreeService.AddPlastDegreeForUserAsync(userPlastDegreePostDTO)) { return(Created("GetAllDergees", userPlastDegreePostDTO.PlastDegreeId)); } return(BadRequest()); }