/// <summary> /// update an existing entity /// </summary> /// <param name="id">entity id to update</param> /// <param name="newEntity">entity with new values</param> /// <returns>number of affected rows.</returns> public int Update(LudothekEntities context, Guid id, TEntity newEntity) { context.Entry(newEntity).State = EntityState.Modified; var numberOfAffectedRows = context.SaveChanges(); return(numberOfAffectedRows); }
/// <summary> /// get a specific branch by its id /// </summary> /// <param name="id">id to search for</param> /// <returns>a branch if one with id exists, otherwise null</returns> public Filiale GetBranch(Guid id) { using (DbContext = new LudothekEntities()) { return(Read(DbContext, f => f.FilialKeyGUID == id).Include(f => f.Verband).FirstOrDefault()); } }
/// <summary> /// get all federations /// </summary> /// <returns>A list of available federations</returns> public List <Verband> GetAllFederations() { using (DbContext = new LudothekEntities()) { return(Read(DbContext).ToList()); } }
/// <summary> /// cancels a rental ( > delete from db) /// </summary> /// <param name="rentalId">id of rental to cancel</param> /// <returns>true if successful, otherwise false</returns> public bool CancelRental(Guid rentalId) { using (DbContext = new LudothekEntities()) { using (var transaction = DbContext.Database.BeginTransaction()) { try { Ausleihe rental = DbContext.Ausleihe.FirstOrDefault(r => r.AusleiheKeyGUID == rentalId); if (rental != null) { rental.Spiel.IsAvailable = true; DbContext.Entry(rental.Spiel).State = EntityState.Modified; DbContext.Ausleihe.Remove(rental); DbContext.SaveChanges(); transaction.Commit(); return(true); } } catch (Exception e) { transaction.Rollback(); return(false); } } } return(false); }
/// <summary> /// save a new branch in the database /// </summary> /// <param name="filiale">branch to write to db</param> /// <returns>true if successful, otherwise false</returns> public bool Create(Filiale filiale) { using (DbContext = new LudothekEntities()) { int affectedRows = Create(DbContext, filiale); return(affectedRows > 0); } }
/// <summary> /// save a new category in the database /// </summary> /// <param name="category">price category to write to db</param> /// <returns>true if successful, otherwise false</returns> public bool Create(Tarifkategorie category) { using (DbContext = new LudothekEntities()) { int affectedRows = Create(DbContext, category); return(affectedRows > 0); } }
/// <summary> /// get all games that are not currently rented /// </summary> /// <returns>a list of available games</returns> public List <Spiel> GetAvailableGames() { using (DbContext = new LudothekEntities()) { return(Read(DbContext, g => g.IsAvailable).ToList()); } }
/// <summary> /// get a specific category by its id /// </summary> /// <param name="id">id to search for</param> /// <returns>a category if one with id exists, otherwise null</returns> public Tarifkategorie GetPriceCategory(Guid id) { using (DbContext = new LudothekEntities()) { return(Read(DbContext, f => f.TarifkategorieKeyGUID == id).Include(c => c.Spiel).FirstOrDefault()); } }
/// <summary> /// get a specific federation by its id /// </summary> /// <param name="id">id to search for</param> /// <returns>a federation if one with id exists, otherwise null</returns> public Verband GetFederation(Guid id) { using (DbContext = new LudothekEntities()) { return(Read(DbContext, f => f.VerbandKeyGUID == id).FirstOrDefault()); } }
/// <summary> /// save a new federation in the database /// </summary> /// <param name="federation">federation to write to db</param> /// <returns>true if successful, otherwise false</returns> public bool Create(Verband federation) { using (DbContext = new LudothekEntities()) { int affectedRows = Create(DbContext, federation); return(affectedRows > 0); } }
/// <summary> /// create a new entity /// </summary> /// <param name="entity">entity to create</param> /// <returns>number of affected rows</returns> public int Create(LudothekEntities context, TEntity entity) { context.Set <TEntity>().Add(entity); var numberOfAffectedRows = context.SaveChanges(); return(numberOfAffectedRows); }
/// <summary> /// add a game to database /// </summary> /// <param name="spiel">game to add</param> /// <returns>true if successful</returns> public bool Create(Spiel spiel) { using (DbContext = new LudothekEntities()) { spiel.IsAvailable = true; int affectedRows = Create(DbContext, spiel); return(affectedRows > 0); } }
/// <summary> /// get a specific customer by id /// </summary> /// <param name="id">id to search for</param> /// <returns>a customer if one with id exists, otherwise null</returns> public Kunde GetCustomer(Guid id) { using (DbContext = new LudothekEntities()) { return(Read(DbContext, c => c.KundenKeyGUID == id) .Include(c => c.Ausleihe) .FirstOrDefault()); } }
/// <summary> /// save a new customer in the database /// </summary> /// <param name="customer">customer to write to db</param> /// <returns>true if successful, otherwise false</returns> public bool Create(Kunde customer) { using (DbContext = new LudothekEntities()) { customer.Filiale = DbContext.Filiale.FirstOrDefault(); // todo, select branch somehow int affectedRows = Create(DbContext, customer); return(affectedRows > 0); } }
/// <summary> /// get a specific rental by its id /// </summary> /// <param name="id">id of rental</param> /// <returns>a rental object</returns> public Ausleihe GetRentalById(Guid id) { using (DbContext = new LudothekEntities()) { return(DbContext.Ausleihe.Where(a => a.AusleiheKeyGUID == id) .Include(r => r.Kunde) .Include(r => r.Spiel) .FirstOrDefault()); } }
/// <summary> /// get a list of all games (unfiltered) /// </summary> /// <returns>return a list of all games</returns> public List <Spiel> GetAllGames() { using (DbContext = new LudothekEntities()) { return(Read(DbContext) .Include(g => g.Tarifkategorie) .Include(g => g.Filiale) .ToList()); } }
/// <summary> /// get a specific game /// </summary> /// <param name="id">id of game as guid</param> /// <returns>a game</returns> public Spiel GetGame(Guid id) { using (DbContext = new LudothekEntities()) { return(DbContext.Spiel.Where(s => s.SpielKeyGUID == id) .Include(g => g.Tarifkategorie) .Include(g => g.Filiale) .FirstOrDefault()); } }
/// <summary> /// get all available rentals /// </summary> /// <returns>all rentals</returns> public List <Ausleihe> GetAllRentals() { using (DbContext = new LudothekEntities()) { return(DbContext.Ausleihe .Include(r => r.Kunde) .Include(r => r.Spiel) .ToList()); } }
/// <summary> /// update a branch /// </summary> /// <param name="filiale">locally updated branch</param> /// <returns>true if successful, otherwise false</returns> public bool Update(Filiale filiale) { var successful = false; using (DbContext = new LudothekEntities()) { if (filiale != null) { successful = Update(DbContext, filiale.FilialKeyGUID, filiale) > 0; } } return(successful); }
/// <summary> /// update a category /// </summary> /// <param name="filiale">locally updated category</param> /// <returns>true if successful, otherwise false</returns> public bool Update(Tarifkategorie category) { var successful = false; using (DbContext = new LudothekEntities()) { if (category != null) { successful = Update(DbContext, category.TarifkategorieKeyGUID, category) > 0; } } return(successful); }
/// <summary> /// update a customer /// </summary> /// <param name="customer">locally updated customer</param> /// <returns>true if successful, otherwise false</returns> public bool Update(Kunde customer) { var successful = false; using (DbContext = new LudothekEntities()) { if (customer != null) { successful = Update(DbContext, customer.KundenKeyGUID, customer) > 0; } } return(successful); }
/// <summary> /// delete a branch /// </summary> /// <param name="id">id of branch to delete</param> /// <returns>true if successful, otherwise false</returns> public bool Delete(Guid id) { var successful = false; Filiale filiale = GetBranch(id); using (DbContext = new LudothekEntities()) { if (filiale != null) { successful = Delete(DbContext, filiale) > 0; } } return(successful); }
/// <summary> /// update a game object /// </summary> /// <param name="game">the game</param> /// <returns>true if successful, otherwise false</returns> public bool Update(Spiel game) { var successful = false; using (DbContext = new LudothekEntities()) { if (game != null) { successful = Update(DbContext, game.SpielKeyGUID, game) > 0; } } return(successful); }
/// <summary> /// delete a category /// </summary> /// <param name="id">id of branch to category</param> /// <returns>true if successful, otherwise false</returns> public bool Delete(Guid id) { var successful = false; Tarifkategorie category = GetPriceCategory(id); using (DbContext = new LudothekEntities()) { if (category != null) { successful = Delete(DbContext, category) > 0; } } return(successful); }
/// <summary> /// delete a branch /// </summary> /// <param name="id">id of branch to delete</param> /// <returns>true if successful, otherwise false</returns> public bool Delete(Guid id) { var successful = false; using (DbContext = new LudothekEntities()) { Filiale filiale = DbContext.Filiale.FirstOrDefault(b => b.FilialKeyGUID == id); if (filiale != null) { successful = Delete(DbContext, filiale) > 0; } } return(successful); }
/// <summary> /// delete a game /// </summary> /// <param name="id">id of game to delete</param> /// <returns>true if successful, otherwise false</returns> public bool Delete(Guid id) { var successful = false; Spiel game = GetGame(id); using (DbContext = new LudothekEntities()) { if (game != null) { successful = Delete(DbContext, game) > 0; } } return(successful); }
/// <summary> /// delete a federation /// </summary> /// <param name="id">id of federation to delete</param> /// <returns>true if successful, otherwise false</returns> public bool Delete(Guid id) { var successful = false; Verband federation = GetFederation(id); using (DbContext = new LudothekEntities()) { if (federation != null) { successful = Delete(DbContext, federation) > 0; } } return(successful); }
public bool Update(Guid id, Verband federation) { var successful = false; Verband federationToUpdate = GetFederation(id); using (DbContext = new LudothekEntities()) { if (federationToUpdate != null) { successful = Update(DbContext, id, federationToUpdate) > 0; } } return(successful); }
/// <summary> /// delete a game /// </summary> /// <param name="id">id of game to delete</param> /// <returns>true if successful, otherwise false</returns> public bool Delete(Guid id) { var successful = false; using (DbContext = new LudothekEntities()) { Spiel game = DbContext.Spiel.FirstOrDefault(g => g.SpielKeyGUID == id); if (game != null) { successful = Delete(DbContext, game) > 0; } } return(successful); }
/// <summary> /// get rentals for a specific user /// </summary> /// <param name="customerId">id of the user</param> /// <param name="onlyActive">only rentals that are active (have not ended) should be returned</param> /// <returns>list of rentals belonging to a customer</returns> public List <Ausleihe> GetRentalsForCustomer(Guid customerId, bool onlyActive = false) { using (DbContext = new LudothekEntities()) { if (onlyActive) { return(Read(DbContext, s => s.Kunde.KundenKeyGUID == customerId && s.Enddatum > DateTime.Now) .Include(r => r.Spiel) .ToList()); } return(Read(DbContext, s => s.Kunde.KundenKeyGUID == customerId) .Include(r => r.Spiel) .ToList()); } }