public void AddConsole(console console) { try { using (db_consolesEntities db = new db_consolesEntities()) { Validate(console); if (db.consoles.Any(x => x.Short_Name == console.Short_Name)) { throw new ArgumentException("The console's short name already exists"); } db.consoles.Add(console); db.SaveChanges(); ListUpdated?.Invoke(); } } catch (ArgumentException) { throw; } catch (Exception) { throw new Exception("Something wrong happened while adding a new console"); } }
public void RemoveCompany(company company) { using (db_consolesEntities db = new db_consolesEntities()) { if (db.companies.FirstOrDefault(x => x.ID == company.ID) != null) { db.Entry(company).State = System.Data.EntityState.Deleted; db.SaveChanges(); ListUpdated?.Invoke(); } } }
public company GetCompany(int ID) { try { using (db_consolesEntities db = new db_consolesEntities()) { return(db.companies.FirstOrDefault(x => x.ID == ID)); } } catch (Exception) { throw new Exception("Something wrong happened while getting the console's info."); } }
public List <company> GetCompanies() { try { using (db_consolesEntities db = new db_consolesEntities()) { return(db.companies.ToList()); } } catch (Exception) { throw new Exception("There are no companies registered."); } }
public void UpdateCompany(company company) { try { using (db_consolesEntities db = new db_consolesEntities()) { Validate(company); db.Entry(company).State = System.Data.EntityState.Modified; db.SaveChanges(); ListUpdated?.Invoke(); } } catch (ArgumentException) { throw; } catch (Exception) { throw new Exception("Something wrong happened while updating the company's info."); } }
public void AddCompany(company company) { try { using (db_consolesEntities db = new db_consolesEntities()) { Validate(company); db.companies.Add(company); db.SaveChanges(); ListUpdated?.Invoke(); } } catch (ArgumentException) { throw; } catch (Exception ex) { throw new Exception("Something wrong happened while adding a new company."); } }