public void MarkFound(int assetId) { var item = _context.LibraryAssets .FirstOrDefault(a => a.Id == assetId); _context.Update(item); item.Status = _context.Statuses.FirstOrDefault(a => a.Name == "Available"); var now = DateTime.Now; // remove any existing checkouts on the item var checkout = _context.Checkouts .FirstOrDefault(a => a.LibraryAsset.Id == assetId); if (checkout != null) { _context.Remove(checkout); } // close any existing checkout history var history = _context.CheckoutHistories .FirstOrDefault(h => h.LibraryAsset.Id == assetId && h.CheckedIn == null); if (history != null) { _context.Update(history); history.CheckedIn = now; } _context.SaveChanges(); }
public async Task <IdentityResult> DeleteAsync(Uzytkownicy user, CancellationToken cancellationToken) { _libraryDbContext.Remove(user); int i = await _libraryDbContext.SaveChangesAsync(cancellationToken); return(await Task.FromResult(i == 1?IdentityResult.Success : IdentityResult.Failed())); }
private void RemoveExistingCheckouts(int assetId) //remove any eisting checkouts on the item { var checkout = _context.Checkouts.FirstOrDefault(co => co.LibraryAsset.Id == assetId); if (checkout != null) { _context.Remove(checkout); } }
public async Task <bool> CheckInItem(Guid assetId) { var now = DateTime.UtcNow; var libraryAsset = await _context.LibraryAssets .FirstAsync(a => a.Id == assetId); _context.Update(libraryAsset); // remove any existing checkouts on the item var checkout = await _context.Checkouts .Include(c => c.Asset) .Include(c => c.LibraryCard) .FirstAsync(a => a.Asset.Id == assetId); if (checkout != null) { _context.Remove(checkout); } // close any existing checkout history var history = await _context.CheckoutHistories .Include(h => h.Asset) .Include(h => h.LibraryCard) .FirstAsync(h => h.Asset.Id == assetId && h.CheckedIn == null); if (history != null) { _context.Update(history); history.CheckedIn = now; } // if there are current holds, check out the item to the earliest // TODO var wasCheckedOutToNewHold = await CheckoutToEarliestHold(assetId); if (wasCheckedOutToNewHold) { // TODO } // otherwise, set item status to available // TODO magic string libraryAsset.AvailabilityStatus = await _context.Statuses .FirstAsync(a => a.Name == "Available"); await _context.SaveChangesAsync(); return(true); }
public void CheckInItem(int id) { var now = DateTime.Now; var item = context.LibraryAssets .First(a => a.Id == id); context.Update(item); // remove any existing checkouts on the item var checkout = context.Checkouts .Include(c => c.LibraryAsset) .Include(c => c.LibraryCard) .FirstOrDefault(a => a.LibraryAsset.Id == id); if (checkout != null) { context.Remove(checkout); } // close any existing checkout history var history = context.CheckoutHistories .Include(h => h.LibraryAsset) .Include(h => h.LibraryCard) .FirstOrDefault(h => h.LibraryAsset.Id == id && h.CheckedIn == null); if (history != null) { context.Update(history); history.CheckedIn = now; } // look for current holds var currentHolds = context.Holds .Include(a => a.LibraryAsset) .Include(a => a.LibraryCard) .Where(a => a.LibraryAsset.Id == id); // if there are current holds, check out the item to the earliest if (currentHolds.Any()) { CheckoutForEarliestHold(id, currentHolds); return; } // otherwise, set item status to available item.Status = context.Statuses.FirstOrDefault(a => a.Name == "Available"); context.SaveChanges(); }
private void CheckoutToEarliestHold(int assetId, IEnumerable <Hold> currentHolds) { var earliestHold = currentHolds.OrderBy(a => a.HoldPlaced).FirstOrDefault(); if (earliestHold == null) { return; } var card = earliestHold.LibraryCard; _context.Remove(earliestHold); _context.SaveChanges(); CheckoutItem(assetId, card.Id); }
public Category DeleteCategory(Category category) { _categoryContext.Remove(category); _categoryContext.SaveChanges(); return(category); }
public void Remove(int bookId) { var book = GetBookById(bookId); _dbContext.Remove(book.Author); _dbContext.SaveChanges(); }
public async Task <bool> MarkFound(Guid assetId) { var libraryAsset = await _context.LibraryAssets .FirstAsync(a => a.Id == assetId); _context.Update(libraryAsset); libraryAsset.AvailabilityStatus = _context.Statuses .First(a => a.Name == AssetStatus.GoodCondition); var now = DateTime.UtcNow; // remove any existing checkouts on the item var checkout = _context.Checkouts .First(a => a.Asset.Id == assetId); if (checkout != null) { _context.Remove(checkout); } // close any existing checkout history var history = _context.CheckoutHistories .First(h => h.Asset.Id == assetId && h.CheckedIn == null); if (history != null) { _context.Update(history); history.CheckedIn = now; } await _context.SaveChangesAsync(); return(true); }
public void Delete(TEntity entity) { if (entity != null) { _context.Remove(entity); _context.SaveChanges(); } }
public async Task <bool> Delete(int id) { var data = await _dbContext.Books.FirstOrDefaultAsync(b => b.Id == id); if (data != null) { _dbContext.Remove(data); } return((await _dbContext.SaveChangesAsync()) > 0); }
public IActionResult Delete(Book book) { using (var db = new LibraryDbContext()) { db.Remove(book); db.SaveChanges(); } return(RedirectToAction("Index")); }
public async Task <IActionResult> DeleteBook(long id) { var book = await context.Book.FindAsync(id); if (book == null) { return(NotFound()); } context.Remove(book); await context.SaveChangesAsync(); return(Ok(id)); }
public async Task <IActionResult> DeleteUser(long id) { var user = await context.Users.FindAsync(id); if (user == null) { return(NotFound()); } context.Remove(user); await context.SaveChangesAsync(); return(Ok(id)); }
public void Delete(int id) { _logger.LogError($"Book with id: {id} DELETE action invoked."); var book = _dbContext .Books .FirstOrDefault(b => b.Id == id); if (book is null) { throw new NotFoundException("Book not found."); } _dbContext.Remove(book); _dbContext.SaveChanges(); }
public void SetDomainState(BaseEntity entity) { switch (entity.Status) { case Status.Added: _context.Add(entity); break; case Status.Updated: _context.Update(entity); break; case Status.Deleted: _context.Remove(entity); break; case Status.Unchanged: break; } }
public void Delete(T entity) { _context.Remove(entity); Save(); }
public async Task <IActionResult> UstawRole(int id, IFormCollection formCollection) { bool KlientCheckbox = false, BibliotekarzCheckbox = false, AdminCheckbox = false; string KlientCheckboxValue = ""; string BibliotekarzCheckboxValue = ""; string AdminCheckboxValue = ""; var user = await _userManager.FindByIdAsync(id.ToString()); if (user == null) { return(NotFound()); } if (!string.IsNullOrEmpty(formCollection["KlientCheckbox"])) { KlientCheckbox = true; } if (!string.IsNullOrEmpty(formCollection["BibliotekarzCheckbox"])) { BibliotekarzCheckbox = true; } if (!string.IsNullOrEmpty(formCollection["AdminCheckbox"])) { AdminCheckbox = true; } if (KlientCheckbox) { KlientCheckboxValue = formCollection["KlientCheckbox"]; } if (BibliotekarzCheckbox) { BibliotekarzCheckboxValue = formCollection["BibliotekarzCheckbox"]; } if (AdminCheckbox) { AdminCheckboxValue = formCollection["AdminCheckbox"]; } bool IsKlient = await _userManager.IsInRoleAsync(user, "Klient"); bool IsBibliotekarz = await _userManager.IsInRoleAsync(user, "Bibliotekarz"); bool IsAdmin = await _userManager.IsInRoleAsync(user, "Admin"); var KlientRoleId = await _context.Role.FirstOrDefaultAsync(m => m.nazwa == "Klient"); var BibliotekarzRoleId = await _context.Role.FirstOrDefaultAsync(m => m.nazwa == "Bibliotekarz"); var AdminRoleId = await _context.Role.FirstOrDefaultAsync(m => m.nazwa == "Admin"); if (KlientCheckbox != IsKlient) { if (IsKlient) { var user_role = await _context.Uzytkownicy_role.FirstOrDefaultAsync(m => m.id_uzytkownika == user.id_uzytkownika && m.id_roli == KlientRoleId.id_roli); _context.Remove(user_role); await _context.SaveChangesAsync(); ViewBag.Klient = ""; } else { await _userManager.AddToRoleAsync(user, "Klient"); await _context.SaveChangesAsync(); ViewBag.Klient = "checked"; } } else { if (IsKlient) { ViewBag.Klient = "checked"; } else { ViewBag.Klient = ""; } } if (BibliotekarzCheckbox != IsBibliotekarz) { if (IsBibliotekarz) { var user_role = await _context.Uzytkownicy_role.FirstOrDefaultAsync(m => m.id_uzytkownika == user.id_uzytkownika && m.id_roli == BibliotekarzRoleId.id_roli); _context.Remove(user_role); await _context.SaveChangesAsync(); ViewBag.Bibliotekarz = ""; } else { await _userManager.AddToRoleAsync(user, "Bibliotekarz"); await _context.SaveChangesAsync(); ViewBag.Bibliotekarz = "checked"; } } else { if (IsBibliotekarz) { ViewBag.Bibliotekarz = "checked"; } else { ViewBag.Bibliotekarz = ""; } } if (AdminCheckbox != IsAdmin) { if (IsAdmin) { var user_role = await _context.Uzytkownicy_role.FirstOrDefaultAsync(m => m.id_uzytkownika == user.id_uzytkownika && m.id_roli == AdminRoleId.id_roli); _context.Remove(user_role); await _context.SaveChangesAsync(); ViewBag.Admin = ""; } else { await _userManager.AddToRoleAsync(user, "Admin"); await _context.SaveChangesAsync(); ViewBag.Admin = "checked"; } } else { if (IsAdmin) { ViewBag.Admin = "checked"; } else { ViewBag.Admin = ""; } } var Input = new InputModelSetRoles { Id = (int)id, Email = user.email, StatusMessage = "Zmiana ról przebiegła pomyślnie" }; return(View(Input)); }
public void Delete(T entity) { dbContext.Remove(entity); SaveChanges(); }
public void Delete(T entity) { _context.Remove(entity); _context.SaveChanges(); }