コード例 #1
0
        public async Task <Email> AddMailAsync(EmailDto emailDto)
        {
            ValidatorEmailService.ValidatorAddMailIfDtoIsNull(emailDto);
            ValidatorEmailService.ValidatorGmailIdLength(emailDto);
            ValidatorEmailService.ValidatorSubjectLength(emailDto);
            ValidatorEmailService.ValidatorSenderLength(emailDto);

            var gmailId = await this.context.Emails
                          .FirstOrDefaultAsync(id => id.GmailId == emailDto.GmailId);

            if (gmailId == null)
            {
                var email = new Email
                {
                    GmailId = emailDto.GmailId,
                    Sender  = emailDto.Sender,
                    InitialRegistrationInData = DateTime.Now,
                    DateReceived = emailDto.DateReceived,
                    Subject      = emailDto.Subject,
                };

                await this.context.Emails.AddAsync(email);

                await this.context.SaveChangesAsync();

                return(email);
            }
            return(null);
        }
コード例 #2
0
        public async Task <Email> AddBodyToCurrentEmailAsync(EmailContentDto emailDto)
        {
            ValidatorEmailService.ValidatorAddBodyToCurrentEmailIfDtoBodyIsNull(emailDto);
            ValidatorEmailService.ValidatorAddBodyToCurrentEmailBodyLength(emailDto);

            var encodeBody = this.encodeDecodeService.Base64Decode(emailDto.Body);

            var email = await this.context.Emails
                        .Include(u => u.User)
                        .Where(gMail => gMail.GmailId == emailDto.GmailId)
                        .SingleOrDefaultAsync();

            var currentUser = await this.context.Users
                              .Where(id => id.Id == emailDto.UserId)
                              .SingleOrDefaultAsync();

            ValidatorEmailService.ValidatorAddBodyToCurrentEmailExistBody(email, emailDto);

            var encriptBody = this.encodeDecodeService.Encrypt(encodeBody);

            if (email.Body == null)
            {
                email.Body   = encriptBody;
                email.User   = currentUser;
                email.UserId = emailDto.UserId;
                email.IsSeen = true;
                await this.context.SaveChangesAsync();
            }
            return(email);
        }
コード例 #3
0
        public async Task <string> ChangeEmailStatusFromClose(EmailDto emailDto)
        {
            ValidatorEmailService.ValidatorSetEmailStatusInvalidApplication(emailDto.GmailId);

            var email = this.context.Emails
                        .Where(gmailId => gmailId.GmailId == emailDto.GmailId)
                        .FirstOrDefault();

            email.EmailStatusId    = (int)EmailStatusesType.New;
            email.SetCurrentStatus = DateTime.Now;
            await this.context.SaveChangesAsync();

            return(emailDto.GmailId);
        }
コード例 #4
0
        public async Task <Email> CheckEmailBodyAsync(EmailContentDto emailDto)
        {
            var email = await this.context.Emails
                        .SingleOrDefaultAsync(gMail => gMail.GmailId == emailDto.GmailId);

            ValidatorEmailService.ValidatorCheckEmailBody(email);

            var currentUser = await this.context.Users
                              .Where(userId => userId.Id == emailDto.UserId)
                              .Select(user => user.UserName)
                              .SingleOrDefaultAsync();

            email.EmailStatusId    = (int)EmailStatusesType.New;
            email.SetCurrentStatus = DateTime.Now;
            await this.context.SaveChangesAsync();

            logger.LogInformation($"Changed email status to New by {currentUser}");
            return(email);
        }
コード例 #5
0
        public async Task AddAttachmentAsync(EmailAttachmentDTO attachmentDTO)
        {
            ValidatorEmailService.ValidatorAddAttachment(attachmentDTO);

            var gmaiId = await this.context.Emails
                         .FirstOrDefaultAsync(id => id.GmailId == attachmentDTO.GmailId);

            if (gmaiId == null)
            {
                var attachment = new EmailAttachment
                {
                    FileName = attachmentDTO.FileName,
                    SizeInKB = attachmentDTO.SizeInKB,
                    GmailId  = attachmentDTO.GmailId
                };

                await this.context.EmailAttachments.AddAsync(attachment);

                await this.context.SaveChangesAsync();
            }
        }
コード例 #6
0
        public async Task <bool> ChangeStatusAsync(EmailStatusIdDto emailStatusId)
        {
            ValidatorEmailService.ValidatorChangeStatus(emailStatusId);

            int status = int.Parse(emailStatusId.StatusId);

            var email = await this.context.Emails
                        .Where(gmailId => gmailId.GmailId == emailStatusId.GmailId)
                        .SingleOrDefaultAsync();

            var currentUser = await this.context.Users
                              .SingleOrDefaultAsync(id => id.Id == emailStatusId.UserId);

            if (status == 1)
            {
                email.User             = currentUser;
                email.UserId           = emailStatusId.UserId;
                email.EmailStatusId    = status;
                email.SetCurrentStatus = DateTime.Now;
                email.IsSeen           = false;
                email.Body             = null;

                await this.context.SaveChangesAsync();

                return(true);
            }
            else if (status == 2)
            {
                email.EmailStatusId    = status;
                email.SetCurrentStatus = DateTime.Now;
                email.IsSeen           = false;
                email.Body             = null;
                await this.context.SaveChangesAsync();

                return(true);
            }

            logger.LogInformation($"Status successfully updated by {currentUser.UserName}.");
            return(true);
        }
コード例 #7
0
        public async Task <bool> SetEmailStatusInvalidApplicationAsync(StatusInvalidApplicationDto dto)
        {
            ValidatorEmailService.ValidatorSetEmailStatusInvalidApplication(dto.GmailId);

            var email = await this.context.Emails
                        .Include(u => u.User)
                        .Where(emailId => emailId.GmailId == dto.GmailId)
                        .FirstOrDefaultAsync();

            var currentUser = await this.context.Users
                              .Where(id => id.Id == dto.UserId)
                              .SingleOrDefaultAsync();

            email.User             = currentUser;
            email.UserId           = dto.UserId;
            email.EmailStatusId    = (int)EmailStatusesType.InvalidApplication;
            email.SetCurrentStatus = DateTime.Now;
            await this.context.SaveChangesAsync();

            logger.LogInformation($"Changed email status to Invalid Application by {currentUser.UserName}");
            return(true);
        }