public async Task <EmailListModel> GetEmailsAsync(int Id, EmailStatusesEnum status) { if (Id == 0) { Id = 1; } var currentUser = await userManager.GetUserAsync(User); var listEmailDTOS = await this.emailService.GetCurrentPageEmailsAsync(Id, status, currentUser); var result = new EmailListModel() { Status = status.ToString(), EmailViewModels = this.emailMapper.MapFrom(listEmailDTOS), CurrentUser = currentUser, PreviousPage = Id == 1 ? 1 : Id - 1, CurrentPage = Id, NextPage = Id + 1, LastPage = await this.emailService.GetEmailsPagesByTypeAsync(status) }; return(result); }
public async Task ChangeStatusAsync(string emailId, EmailStatusesEnum newEmaiLStatus, User currentUser) { var email = await this.dbcontext.Emails.FirstOrDefaultAsync(e => e.Id == emailId); if (email == null) { throw new ArgumentNullException("Email not found!"); } logger.LogInformation($"Status of email with id {emailId} has been updated by {currentUser.Id} at {DateTime.Now}. From status: {email.Status} to status: {newEmaiLStatus}."); email.Status = newEmaiLStatus; email.LastStatusUpdate = DateTime.Now; email.UserId = currentUser.Id; email.IsOpne = false; this.dbcontext.Emails.Update(email); await this.dbcontext.SaveChangesAsync(); }
public async Task <ICollection <EmailDTO> > GetCurrentPageEmailsAsync(int page, EmailStatusesEnum typeOfEmail, User user) { List <Email> emails; if (await userManager.IsInRoleAsync(user, "OPERATOR") && (typeOfEmail == EmailStatusesEnum.Open)) { emails = await this.dbcontext.Emails .Where(e => e.Status == typeOfEmail) .OrderByDescending(e => e.RegisteredInDataBase) .Skip((page - 1) * 15) .Take(150) .Include(a => a.Attachments) .Include(e => e.User) .Include(e => e.LoanApplication) .Where(e => e.UserId == user.Id) .ToListAsync(); } else { emails = await this.dbcontext.Emails .Where(e => e.Status == typeOfEmail) .OrderByDescending(e => e.RegisteredInDataBase) .Skip((page - 1) * 15) .Take(150) .Include(a => a.Attachments) .Include(e => e.User) .Include(e => e.LoanApplication) .ToListAsync(); } if (emails == null) { throw new ArgumentNullException("No emails found!"); } emails = await DecodeEmails(emails); return(this.emailDTOMapper.MapFrom(emails)); }
public async Task <int> GetEmailsPagesByTypeAsync(EmailStatusesEnum statusOfEmail) { var totalEmails = await this.dbcontext.Emails.Where(e => e.Status == statusOfEmail).CountAsync(); return(totalEmails % 15 == 0 ? totalEmails / 15 : totalEmails / 15 + 1); }