public async Task <bool> DeleteAsync(CustomerEntity customer) { _context.Remove(customer); await _context.SaveChangesAsync(); return(true); }
public async Task <bool> DeleteAsync(SiteEntity siteEntity) { _context.Remove(siteEntity); await _context.SaveChangesAsync(); return(true); }
// POST: AjaxDeleteCharacter public IActionResult AjaxDeleteCharacter() { try { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); using (var context = new SiteDbContext()) { Characters character = context.Characters .Where(r => r.UserId == User.FindFirstValue(ClaimTypes.NameIdentifier)) .Select(r => r).FirstOrDefault(); var inventory = context.Inventory .Where(r => r.UserId == User.FindFirstValue(ClaimTypes.NameIdentifier)) .Select(r => r).ToList(); foreach (var item in inventory) { context.Remove(item); } var atBattle = context.AtBattlePVE .Where(r => r.UserId == User.FindFirstValue(ClaimTypes.NameIdentifier)) .Select(r => r).FirstOrDefault(); if (atBattle != null) { context.Remove(atBattle); } var atWork = context.AtWork .Where(r => r.UserId == User.FindFirstValue(ClaimTypes.NameIdentifier)) .Select(r => r).FirstOrDefault(); if (atWork != null) { context.Remove(atWork); } var companions = context.Teams .Where(r => r.UserId == User.FindFirstValue(ClaimTypes.NameIdentifier)) .Select(r => r).ToList(); foreach (var item in companions) { context.Remove(item); } var heroQuests = context.HeroesQuestsState .Where(r => r.UserId == User.FindFirstValue(ClaimTypes.NameIdentifier)) .Select(r => r).ToList(); foreach (var item in heroQuests) { context.Remove(item); } Gold gold = context.Gold .Where(r => r.UserId == userId) .Select(r => r).FirstOrDefault(); gold.Number = 0; if (gold != null) { context.Update(gold); } if (character != null) { context.Remove(character); } context.SaveChanges(); } Response.StatusCode = (int)System.Net.HttpStatusCode.OK; return(Json(new { success = true })); } catch { Response.StatusCode = (int)System.Net.HttpStatusCode.Forbidden; return(Json(new { success = false })); } }