Пример #1
0
        public async Task <OperationResult> CreateAnnouncement(AnnouncementSaveDto announcement, string login)
        {
            var currentUser = await userRepository.GetUserByLogin(login);

            var announcementModel = mapper.Map <AnnouncementSaveDto, Announcement>(announcement);

            announcementModel.UserId      = currentUser.Id;
            announcementModel.DateCreated = DateTime.Now;
            await repository.AddAsync(announcementModel);

            var result = await repository.SaveChangesAsync();

            if (result > 0)
            {
                return(new OperationResult()
                {
                    IsSuccessful = true,
                    Payload = announcementModel
                });
            }
            else
            {
                return(OtherServices.GetIncorrectDatabaseConnectionResult());
            }
        }
        public async Task AddAsync(AnnouncementToAdd model)
        {
            var entity = _mapper.Map <AnnouncementEf>(model);

            await _announcementRepository.AddAsync(entity);

            if (model.CanSendEmail)
            {
                await SendEmailAsync(entity);
            }
        }
Пример #3
0
        public async Task <Unit> Handle(AddAnnouncementCommand request, CancellationToken cancellationToken)
        {
            if (_announcementRepository.CountAllByDate(request.PublicationDate, request.UserId).Result >= 5)
            {
                throw new ArgumentException("The number of the same publication date cannot be over than 5.");
            }

            var announcement = new Domain.Announcement(request.Id, request.Title, request.Content, request.PublicationDate, request.UserId);

            await _announcementRepository.AddAsync(announcement);

            await _announcementRepository.SaveChangesAsync();

            return(Unit.Value);
        }
Пример #4
0
        public async Task <SaveAnnouncementResponse> SaveAsync(Announcement address)
        {
            try
            {
                await _addressRepository.AddAsync(address);

                await _unitOfWork.CompleteAsync();

                return(new SaveAnnouncementResponse(address));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new SaveAnnouncementResponse($"An error occurred when saving the address: {ex.Message}"));
            }
        }
Пример #5
0
        public async Task <ApiResult <AddPropertyAnnouncementOutput> > AddPropertyAnnouncement([FromBody] AddPropertyAnnouncementInput input, CancellationToken cancelToken)
        {
            if (Authorization == null)
            {
                return(new ApiResult <AddPropertyAnnouncementOutput>(APIResultCode.Unknown, new AddPropertyAnnouncementOutput {
                }, APIResultMessage.TokenNull));
            }
            if (string.IsNullOrWhiteSpace(input.Content))
            {
                throw new NotImplementedException("公告内容信息为空!");
            }
            if (string.IsNullOrWhiteSpace(input.Title))
            {
                throw new NotImplementedException("公告标题信息为空!");
            }

            var user = _tokenRepository.GetUser(Authorization);

            if (user == null)
            {
                return(new ApiResult <AddPropertyAnnouncementOutput>(APIResultCode.Unknown, new AddPropertyAnnouncementOutput {
                }, APIResultMessage.TokenError));
            }

            var entity = await _announcementRepository.AddAsync(new AnnouncementDto
            {
                Content            = input.Content,
                Summary            = input.Summary,
                Title              = input.Title,
                DepartmentValue    = Department.WuYe.Value,
                DepartmentName     = Department.WuYe.Name,
                SmallDistrictArray = user.SmallDistrictId,
                OperationTime      = DateTimeOffset.Now,
                OperationUserId    = user.Id.ToString(),
                CommunityId        = user.CommunityId,
                CommunityName      = user.CommunityName,
                SmallDistrictId    = user.SmallDistrictId,
                SmallDistrictName  = user.SmallDistrictName,
                StreetOfficeId     = user.StreetOfficeId,
                StreetOfficeName   = user.StreetOfficeName
            }, cancelToken);

            if (!string.IsNullOrWhiteSpace(input.AnnexId))
            {
                await _announcementAnnexRepository.AddAsync(new AnnouncementAnnexDto
                {
                    AnnexContent    = input.AnnexId,
                    AnnouncementId  = entity.Id.ToString(),
                    OperationTime   = DateTimeOffset.Now,
                    OperationUserId = user.Id.ToString()
                }, cancelToken);
            }

            var url        = (await _announcementAnnexRepository.GetAsync(entity.Id.ToString()))?.AnnexContent;
            var userEntity = await _userRepository.GetForIdAsync(entity.CreateOperationUserId);

            await AnnouncementPushRemind(new AnnouncementPushModel
            {
                Content        = entity.Content,
                Id             = entity.Id.ToString(),
                ReleaseTime    = entity.CreateOperationTime.Value.ToString("yyyy'-'MM'-'dd' 'HH':'mm':'ss"),
                Summary        = entity.Summary,
                Title          = entity.Title,
                Url            = url,
                CreateUserName = userEntity?.Name
            }, entity.SmallDistrictArray);

            return(new ApiResult <AddPropertyAnnouncementOutput>(APIResultCode.Success, new AddPropertyAnnouncementOutput {
                Id = entity.Id.ToString()
            }));
        }
Пример #6
0
 public async Task <EntityEntry <T> > AddAsync <T>(T entity) where T : Announcement
 {
     return(await _announcementRepository.AddAsync(entity));
 }
Пример #7
0
        /// <summary>
        /// Crear un comunicado
        /// </summary>
        /// <param name="announcement">Objeto que contiene la información del comunicado</param>
        /// <param name="file">Imagen del comunicado</param>
        /// <returns></returns>
        public async Task CreateAnnouncementAsync(AnnouncementDto announcement, IFormFile file)
        {
            Announcement announcementEntity = await ManageImageBlobAsync(announcement, file, AnnouncementAction.Save).ConfigureAwait(false);

            await announcementRepository.AddAsync(announcementEntity).ConfigureAwait(false);
        }