public async Task <IActionResult> DeleteEmail(DeleteEmailAddressModel model) { var accessToken = await _dbContext .AccessToken .SingleOrDefaultAsync(t => t.Value == model.AccessToken); var app = await _developerApiService.AppInfoAsync(accessToken.ApplyAppId); var user = await _userManager.FindByIdAsync(model.OpenId); var useremail = await _dbContext.UserEmails.SingleOrDefaultAsync(t => t.EmailAddress == model.ThatEmail.ToLower()); if (useremail == null) { return(this.Protocal(ErrorType.NotFound, $"Can not find your email:{model.ThatEmail}")); } if (useremail.OwnerId != user.Id) { return(this.Protocal(ErrorType.Unauthorized, $"The account you tried to authorize is not an account with id: {model.OpenId}")); } if (!_dbContext.LocalAppGrant.Exists(t => t.AppID == accessToken.ApplyAppId && t.APIUserId == user.Id)) { return(Json(new AiurProtocal { Code = ErrorType.Unauthorized, Message = "This user did not grant your app!" })); } if (!app.App.ConfirmEmail) { return(this.Protocal(ErrorType.Unauthorized, "You app is not allowed to send confirmation email!")); } _dbContext.UserEmails.Remove(useremail); await _dbContext.SaveChangesAsync(); return(this.Protocal(ErrorType.Success, $"Successfully deleted the email: {model.ThatEmail}!")); }
public async Task <int> DeleteEmailAddress(DeleteEmailAddressModel model) { try { _dbconnection.StoredProcedure = Constants.DeleteEmailAddressStoredProcedure; _dbconnection.Parameters = model; return(await _dapperRepository.Execute(_dbconnection)); } catch (Exception ex) { throw ex; } }
public async Task<IActionResult> DeleteEmail(DeleteEmailAddressModel model) { var user = await _grantChecker.EnsureGranted(model.AccessToken, model.OpenId, t => t.ConfirmEmail); var userEmails = _dbContext.UserEmails.Where(t => t.OwnerId == user.Id); var useremail = await userEmails.SingleOrDefaultAsync(t => t.EmailAddress.ToLower() == model.ThatEmail.ToLower()); if (useremail == null) { return this.Protocol(ErrorType.NotFound, $"Can not find your email:{model.ThatEmail}"); } if (await userEmails.CountAsync() == 1) { return this.Protocol(ErrorType.NotEnoughResources, $"Can not delete Email: {model.ThatEmail}, because it was your last Email address!"); } _dbContext.UserEmails.Remove(useremail); await _dbContext.SaveChangesAsync(); return this.Protocol(ErrorType.Success, $"Successfully deleted the email: {model.ThatEmail}!"); }
public async Task <ActionResult> DeleteEmailAddress([FromBody] DeleteEmailAddressModel model) { var result = await _addressbookservice.DeleteEmailAddress(model); return(Json(new { success = true, response = result })); }