예제 #1
0
 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");
     }
 }
예제 #2
0
 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();
         }
     }
 }
예제 #3
0
 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.");
     }
 }
예제 #4
0
 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.");
     }
 }
예제 #5
0
 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.");
     }
 }
예제 #6
0
 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.");
     }
 }