public async Task Delete(string appId) { var application = await _context.Applications .FirstOrDefaultAsync(app => app.Id.ToString() == appId) .ConfigureAwait(false); _context.Applications.Remove(application); await _context.SaveChangesAsync(); }
public async Task ChangePasswordAsync(string username, string currentPassword, string newPassword) { var user = await _userManager.FindByNameAsync(username); var isPasswordCorrect = await _userManager.CheckPasswordAsync(user, currentPassword); if (!isPasswordCorrect) { // To implement properly throw new ArgumentException(Constants.UserWrongPass); } else { var result = await _userManager.ChangePasswordAsync(user, currentPassword, newPassword); if (!result.Succeeded) { // To implement properly throw new ArgumentException(Constants.UserInvalidPass); } else { user.IsPasswordChanged = true; var claim = _context.UserClaims.FirstOrDefault(userclaim => userclaim.ClaimType == "IsPasswordChanged" && userclaim.UserId == user.Id); claim.ClaimValue = "True"; await _context.SaveChangesAsync(); } } }
public async Task ChangeStatusAsync(string id, EmailStatus newStatus) { var email = await _context.Emails .FirstOrDefaultAsync(mail => mail.Id.ToString() == id) .ConfigureAwait(false); if (newStatus == EmailStatus.New) { email.ToNewStatus = DateTime.UtcNow; if (email.Status == EmailStatus.NotReviewed) { await this.AddBodyAsync(email.Id); } } else if (newStatus == EmailStatus.Closed) { email.ToTerminalStatus = DateTime.UtcNow; } email.ToCurrentStatus = DateTime.UtcNow; email.Status = newStatus; await _context.SaveChangesAsync().ConfigureAwait(false); }
private async Task AddToContext(List <EmailGmail> gmailEmails) { foreach (var email in gmailEmails) { var newDomainEmail = email.MapToDomainModel(); var domainEmail = _context.Emails.Add(newDomainEmail); if (email.Attachments.Count != 0) { foreach (var attachment in email.Attachments) { var newDomainAttachment = attachment.MapToDomainModel(); newDomainAttachment.EmailId = domainEmail.Entity.Id; _context.Attachments.Add(newDomainAttachment); } } } await _context.SaveChangesAsync().ConfigureAwait(false); }