/// <inheritdoc /> public async Task <ClubAdministrationDTO> AddAdministratorAsync(ClubAdministrationDTO adminDTO) { var adminType = await _adminTypeService.GetAdminTypeByNameAsync(adminDTO.AdminType.AdminTypeName); adminDTO.Status = DateTime.Now < adminDTO.EndDate || adminDTO.EndDate == null; var admin = new ClubAdministration() { StartDate = adminDTO.StartDate ?? DateTime.Now, EndDate = adminDTO.EndDate, AdminTypeId = adminType.ID, ClubId = adminDTO.ClubId, UserId = adminDTO.UserId, Status = adminDTO.Status }; var user = await _userManager.FindByIdAsync(adminDTO.UserId); string role; switch (adminType.AdminTypeName) { case Roles.KurinHead: role = Roles.KurinHead; break; case Roles.KurinHeadDeputy: role = Roles.KurinHeadDeputy; break; default: role = Roles.KurinSecretary; break; } try { await _userManager.AddToRoleAsync(user, role); } catch (Exception e) { Console.WriteLine(e.Message); ExceptionDispatchInfo.Capture(e).Throw(); } await CheckClubHasAdmin(adminDTO.ClubId, adminType.AdminTypeName); await _repositoryWrapper.ClubAdministration.CreateAsync(admin); await _repositoryWrapper.SaveAsync(); adminDTO.ID = admin.ID; return(adminDTO); }
/// <inheritdoc /> public async Task <ClubAdministrationDTO> AddClubAdminAsync(ClubAdministrationDTO createdAdmin) { var adminType = await _adminTypeService.GetAdminTypeByNameAsync(createdAdmin.AdminTypeName); createdAdmin.AdminTypeId = adminType.ID; ClubAdministration newClubAdmin = _mapper.Map <ClubAdministrationDTO, ClubAdministration>(createdAdmin); await _repoWrapper.ClubAdministration.CreateAsync(newClubAdmin); await _repoWrapper.SaveAsync(); return(_mapper.Map <ClubAdministration, ClubAdministrationDTO>(newClubAdmin)); }
public async Task <IActionResult> AddToClubAdministration(int clubId, [FromBody] ClubAdministrationDTO createdAdmin) { try { await _clubService.GetClubInfoByIdAsync(clubId); createdAdmin.ClubId = clubId; await _clubAdministrationService.AddClubAdminAsync(createdAdmin); return(Json(true)); } catch (Exception) { return(Json(false)); } }
public int AddToClubAdministration([FromBody] ClubAdministrationDTO createdAdmin) { try { var adminType = _repoWrapper.AdminType .FindByCondition(i => i.AdminTypeName == createdAdmin.AdminType).FirstOrDefault(); int AdminTypeId; if (adminType == null) { var newAdminType = new AdminType() { AdminTypeName = createdAdmin.AdminType }; _repoWrapper.AdminType.Create(newAdminType); _repoWrapper.Save(); adminType = _repoWrapper.AdminType .FindByCondition(i => i.AdminTypeName == createdAdmin.AdminType).FirstOrDefault(); AdminTypeId = adminType.ID; } else { AdminTypeId = adminType.ID; } ClubAdministration newClubAdmin = new ClubAdministration() { ClubMembersID = createdAdmin.adminId, StartDate = createdAdmin.startdate, EndDate = createdAdmin.enddate, ClubId = createdAdmin.clubIndex, AdminTypeId = AdminTypeId }; _repoWrapper.GetClubAdministration.Create(newClubAdmin); _repoWrapper.Save(); return(1); } catch (Exception e) { return(0); } }
/// <inheritdoc /> public async Task <ClubAdministrationDTO> AddAdministratorAsync(ClubAdministrationDTO adminDTO) { var adminType = await _adminTypeService.GetAdminTypeByNameAsync(adminDTO.AdminType.AdminTypeName); var admin = new ClubAdministration() { StartDate = adminDTO.StartDate ?? DateTime.Now, EndDate = adminDTO.EndDate, AdminTypeId = adminType.ID, ClubId = adminDTO.ClubId, UserId = adminDTO.UserId }; var user = await _userManager.FindByIdAsync(adminDTO.UserId); var role = adminType.AdminTypeName == "Голова Куреня" ? "Голова Куреня" : "Діловод Куреня"; try { await _userManager.AddToRoleAsync(user, role); } catch (Exception e) { Console.WriteLine(e.Message); throw e; } if (role == "Голова Куреня") { await CheckClubHasHead(adminDTO.ClubId); } await _repositoryWrapper.ClubAdministration.CreateAsync(admin); await _repositoryWrapper.SaveAsync(); adminDTO.ID = admin.ID; return(adminDTO); }
/// <inheritdoc /> public async Task <ClubAdministrationDTO> EditAdministratorAsync(ClubAdministrationDTO adminDTO) { var admin = await _repositoryWrapper.ClubAdministration.GetFirstOrDefaultAsync(a => a.ID == adminDTO.ID); var adminType = await _adminTypeService.GetAdminTypeByNameAsync(adminDTO.AdminType.AdminTypeName); if (adminType.ID == admin.AdminTypeId) { admin.StartDate = adminDTO.StartDate ?? DateTime.Now; admin.EndDate = adminDTO.EndDate; _repositoryWrapper.ClubAdministration.Update(admin); await _repositoryWrapper.SaveAsync(); } else { await RemoveAdministratorAsync(adminDTO.ID); adminDTO = await AddAdministratorAsync(adminDTO); } return(adminDTO); }