/// <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);
        }
Exemplo n.º 2
0
        /// <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));
        }
Exemplo n.º 3
0
        public IActionResult DeleteFromAdmins(int adminId, int clubIndex)
        {
            ClubAdministration admin = _repoWrapper.GetClubAdministration.FindByCondition(i => i.ID == adminId).FirstOrDefault();

            if (admin != null)
            {
                _repoWrapper.GetClubAdministration.Delete(admin);
                _repoWrapper.Save();
                return(RedirectToAction("ClubAdmins", new { index = clubIndex }));
            }
            else
            {
                return(RedirectToAction("HandleError", "Error", new { code = 505 }));
            }
        }
Exemplo n.º 4
0
        public int AddEndDate([FromBody] AdminEndDateDTO adminEndDate)
        {
            try
            {
                ClubAdministration admin = _repoWrapper.GetClubAdministration.FindByCondition(i => i.ID == adminEndDate.adminId).FirstOrDefault();

                admin.EndDate = adminEndDate.enddate;

                _repoWrapper.GetClubAdministration.Update(admin);
                _repoWrapper.Save();

                return(1);
            }
            catch (Exception e)
            {
                return(0);
            }
        }
Exemplo n.º 5
0
        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);
        }