/// <summary> /// Deletes book from table /// </summary> /// <param name="adminId"></param> /// <param name="bookId"></param> /// <param name="amount"></param> /// <returns>bool</returns> public bool DeleteBook(int adminId, int bookId, int amount = 0) { bool isBookDeleted = false; if (Security.AdminCheck(adminId) && SessionTimer.AdminCheckSessionTimer(adminId) == false) { using (var db = new EFContext()) { var book = db.Books?.FirstOrDefault(x => x.Id == bookId); if (book != null) { if (amount == 0) { book.Amount--; db.Update(book); } else if (amount > 0) { book.Amount -= amount; db.Update(book); } if (book.Amount <= 0) { db.Remove(book); } db.SaveChanges(); SessionTimer.AdminSetSessionTimer(adminId); isBookDeleted = true; } } } return(isBookDeleted); }
public async Task <int> DeleteAsync(int id) { var entity = await _context.ClassificationCriterion.SingleAsync(c => c.Id == id); _context.Remove(entity); return(await _context.SaveChangesAsync()); }
public async Task <Result> DeleteOrder(Guid orderId) { var result = new Result(); try { var currentOrder = await _context.Orders.FirstAsync( o => o.Id == orderId ); if (currentOrder == null) { throw new ArgumentNullException(nameof(currentOrder)); } _context.Remove <Order>(currentOrder); await _context.SaveChangesAsync(); result.IsCompleted = true; } catch (Exception ex) { result.Message = _builder.Build(ex.Message, nameof(EFOrderRepository), nameof(DeleteOrder)); result.IsCompleted = true; } return(result); }
public async Task <int> DeleteAsync(int id) { var entity = await _context.Publication.SingleAsync(p => p.Id == id); _context.Remove(entity); return(await _context.SaveChangesAsync()); }
public async Task <int> DeleteAsync(int id) { var entity = await _context.Field.SingleAsync(f => f.Id == id); _context.Remove(entity); return(await _context.SaveChangesAsync()); }
public async Task <int> DeleteAsync(int id) { var entity = _context.User.Single(u => u.Id == id); _context.Remove(entity); return(await _context.SaveChangesAsync()); }
public IActionResult ConfirmDelete(int id) { Game game = _context.Games.Where(g => g.Id == id).FirstOrDefault(); _context.Remove(game); _context.SaveChanges(); return(RedirectToAction("Index")); }
public static void DropStudent() { using (var context = new EFContext()) { User u = context.User.Find(1); context.Remove(u); context.SaveChanges(); } }
public async Task DeleteAsync(int id) { using (var context = new EFContext()) { var entity = Activator.CreateInstance <T>(); entity.Id = id; context.Remove(entity); await context.SaveChangesAsync(); } }
public async Task <int> DeleteAsync(int id) { var entity = await _context.ExclusionCriterion.SingleOrDefaultAsync(e => e.Id == id); if (entity == null) { return(0); } _context.Remove(entity); return(await _context.SaveChangesAsync()); }
public virtual async Task DeleteAsync(int id) { var dbEntry = await _context.Set <T>().FindAsync(id); if (dbEntry == null) { throw new Exception("Значения модели не описаны"); } _context.Remove(dbEntry); await _context.SaveChangesAsync(); }
public async Task <int> DeleteAsync(int id) { var entity = _context.TaskDelegation.SingleOrDefault(u => u.Id == id); if (entity == null) { return(0); } _context.Remove(entity); return(await _context.SaveChangesAsync()); }
public IActionResult ConfirmarExclusao(int id) { if (id == null) { return(NotFound()); } var carro = contexto.Carros.FirstOrDefault(x => x.CarroId == id); contexto.Remove(carro); contexto.SaveChanges(); return(RedirectToAction(nameof(Index))); }
public IActionResult DeleteById(int userId) { User user = _context.Find <User>(userId); if (user != null) { _context.Remove <User>(user); _context.SaveChanges(); return(NoContent()); } return(NotFound()); }
public ContentResult DeleteProduct(int id) { try { var product = context.Dbproduct.FirstOrDefault(w => w.Id == id); context.Remove(product); context.SaveChanges(); return(Content("Product successfuly deleted")); } catch (Exception ex) { return(Content("Error" + ex.Message)); } }
public async Task <IActionResult> DeleteAccount() { UserAccount user = await _userManager.FindByNameAsync(this.User.Identity.Name); var loginAcc = _context.Users.FirstOrDefault(t => t.Id == user.Id); if (loginAcc != null) { _context.Remove(loginAcc); _context.SaveChanges(); return(Content("Your account is deleted!")); } return(Content("Action not happened!")); }
private void Set(T model, EntityState state) { if (state == EntityState.Added) { _context.Add(model); } else if (state == EntityState.Modified) { _context.Update(model); } else if (state == EntityState.Deleted) { _context.Remove(model); } }
public async Task<bool> Delete(string user) { try { var tbl = await _db.AppUser.Where(m => m.UserName == user).FirstOrDefaultAsync(); _db.Remove(tbl); await _db.SaveChangesAsync(); return true; } catch { return false; } }
public ContentResult deletezakaz(int id, [FromBody] ZakazClient model) { var zakaz = context.Dbzakaz.FirstOrDefault(t => t.Id == id); if (zakaz != null) { context.Remove(zakaz); context.SaveChanges(); return(Content("deleted zakaz")); } else { return(Content("Didnt delete zakaz")); } }
public ContentResult deletecategory(int id, [FromBody] UserViewModel model) { var user = context.Dbuser.FirstOrDefault(t => t.Id == id); if (user != null) { context.Remove(user); context.SaveChanges(); return(Content("deleted user")); } else { return(Content("Didnt delete user")); } }
public async Task <bool> Delete(string ma) { try { var tbl = await _db.TblBp.FindAsync(ma); _db.Remove(tbl); await _db.SaveChangesAsync(); return(true); } catch { return(false); } }
public async Task <bool> DeleteFileContainer(FileContainer container) { if (container != null) { try { context.Remove(container); await context.SaveChangesAsync(); return(true); } catch (Exception e) { //TODO: Logging } } return(false); }
public async Task <int> DeleteEmployee(int id) { try { var employee = await _context.Employee.Where(x => x.ID == id).FirstOrDefaultAsync(); if (employee != null) { _context.Remove(employee); await _context.SaveChangesAsync(); } return(1); } catch (Exception ex) { throw ex; } }
public IActionResult Delete([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var animal = _context.Animals.SingleOrDefault(x => x.Id == id); if (animal == null) { return(BadRequest(new { invalid = "Animal is not found" })); } _context.Remove(animal); _context.SaveChanges(); return(Ok(animal.Id)); }
private async void SetDone(object sender, RoutedEventArgs e) { // Get TaskID var id = (int)((sender as Button).CommandParameter); // Remove record using (var db = new EFContext()) { Task t = db.TaskSet.SingleOrDefault(x => x.TaskID == id); if (t == null) { return; // not found :-( } db.Remove(t); var count = await db.SaveChangesAsync(); SetStatus(count + " records deleted!"); await this.LoadTaskSet(); } }
public void Remove(T entity) => context.Remove(entity);
public void Delete(TEntity entity) { _context.Remove(entity); _context.SaveChanges(); }
public void Remove(T entiry) { efContext.Remove(entiry); }
public async Task DeletePhone(Phone phone) { _dbContext.Remove(phone); await _dbContext.SaveChangesAsync(); }