Esempio n. 1
0
        /// <inheritdoc />
        public async Task <CityMembersDTO> AddFollowerAsync(int cityId, string userId)
        {
            var oldCityMember = await _repositoryWrapper.CityMembers
                                .GetFirstOrDefaultAsync(i => i.UserId == userId);

            if (oldCityMember != null)
            {
                _repositoryWrapper.CityMembers.Delete(oldCityMember);
                await _repositoryWrapper.SaveAsync();
            }

            var oldCityAdmins = await _repositoryWrapper.CityAdministration
                                .GetAllAsync(i => i.UserId == userId && (DateTime.Now < i.EndDate || i.EndDate == null));

            foreach (var admin in oldCityAdmins)
            {
                await _cityAdministrationService.RemoveAdministratorAsync(admin.ID);
            }

            var cityMember = new CityMembers()
            {
                CityId     = cityId,
                IsApproved = false,
                UserId     = userId,
                User       = await _userManager.FindByIdAsync(userId)
            };

            await _repositoryWrapper.CityMembers.CreateAsync(cityMember);

            await _repositoryWrapper.SaveAsync();

            return(_mapper.Map <CityMembers, CityMembersDTO>(cityMember));
        }
Esempio n. 2
0
        public async Task <IActionResult> RemoveAdmin(int adminId)
        {
            await _cityAdministrationService.RemoveAdministratorAsync(adminId);

            _logger.LogInformation($"Admin with ID {{{adminId}}} was removed.");

            return(Ok());
        }