public void Update(Age Age) { try { Age age = GetAgeByID(Age.ForAgesId); var a = GetAgeList().Where(a => !a.ForAgesId.Equals(Age.ForAgesId) && a.Description.Equals(Age.Description)).FirstOrDefault(); if (age != null) { if (a != null) { throw new Exception("The Age name exist."); } using var context = new BookManagementDBContext(); context.Ages.Update(Age); context.SaveChanges(); } else { throw new Exception("The Age does not exist."); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Update(Category Category) { try { Category Cate = GetCategoryByID(Category.CategoryId); var cate = GetCategoryList().Where(c => !c.CategoryId.Equals(Category.CategoryId) && c.CategoryName.Equals(Category.CategoryName)).FirstOrDefault(); if (Cate != null) { if (cate != null) { throw new Exception("The Category name exist."); } using var context = new BookManagementDBContext(); context.Categories.Update(Category); context.SaveChanges(); } else { throw new Exception("The Category does not exist."); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public Category GetCategoryByName(string CategoryName) { Category Category = null; try { using var context = new BookManagementDBContext(); Category = context.Categories.SingleOrDefault(m => m.CategoryName == CategoryName); } catch (Exception ex) { throw new Exception(ex.Message); } return(Category); }
public Company GetCompanyByName(string CompanyName) { Company Company = null; try { using var context = new BookManagementDBContext(); Company = context.Companies.SingleOrDefault(m => m.CompanyName.Equals(CompanyName)); } catch (Exception ex) { throw new Exception(ex.Message); } return(Company); }
public Age GetAgeByID(string ForAgesId) { Age Age = null; try { using var context = new BookManagementDBContext(); Age = context.Ages.SingleOrDefault(m => m.ForAgesId == ForAgesId); } catch (Exception ex) { throw new Exception(ex.Message); } return(Age); }
public User GetUserByEmail(string email) { User User = null; try { using var context = new BookManagementDBContext(); User = context.Users.SingleOrDefault(m => m.Email.Equals(email) && m.RoleId == 1); } catch (Exception ex) { throw new Exception(ex.Message); } return(User); }
public IEnumerable <Report> GetReportList() { var Reports = new List <Report>(); try { using var context = new BookManagementDBContext(); Reports = context.Reports.ToList(); } catch (Exception ex) { throw new Exception(ex.Message); } return(Reports); }
public Product GetProductByName(string ProductName) { Product Product = null; try { using var context = new BookManagementDBContext(); Product = context.Products.SingleOrDefault(m => m.ProductName == ProductName); } catch (Exception ex) { throw new Exception(ex.Message); } return(Product); }
public Report GetReportByID(int id) { Report Report = null; try { using var context = new BookManagementDBContext(); Report = context.Reports.SingleOrDefault(m => m.Id == id); } catch (Exception ex) { throw new Exception(ex.Message); } return(Report); }
public IEnumerable <Report> GetReportsByProductID(string proID) { var Reports = new List <Report>(); try { using var context = new BookManagementDBContext(); Reports = context.Reports.Where(r => r.ProductId.Equals(proID)).ToList(); } catch (Exception ex) { throw new Exception(ex.Message); } return(Reports); }
public IEnumerable <User> GetUserList() { var Users = new List <User>(); try { using var context = new BookManagementDBContext(); Users = context.Users.Where(u => u.RoleId == 1).ToList(); } catch (Exception ex) { throw new Exception(ex.Message); } return(Users); }
public IEnumerable <Product> GetProductList() { var Products = new List <Product>(); try { using var context = new BookManagementDBContext(); Products = context.Products.ToList(); Products.Sort((n1, n2) => Int32.Parse(n1.ProductId.Substring(1)).CompareTo(Int32.Parse(n2.ProductId.Substring(1)))); } catch (Exception ex) { throw new Exception(ex.Message); } return(Products); }
public IEnumerable <Age> GetAgeList() { var Ages = new List <Age>(); try { using var context = new BookManagementDBContext(); Ages = context.Ages.ToList(); Ages.Sort((n1, n2) => Int32.Parse(n1.ForAgesId.Substring(1)).CompareTo(Int32.Parse(n2.ForAgesId.Substring(1)))); } catch (Exception ex) { throw new Exception(ex.Message); } return(Ages); }
public IEnumerable <Company> GetCompanyList() { var Companies = new List <Company>(); try { using var context = new BookManagementDBContext(); Companies = context.Companies.ToList(); Companies.Sort((n1, n2) => Int32.Parse(n1.CompanyId.Substring(2)).CompareTo(Int32.Parse(n2.CompanyId.Substring(2)))); } catch (Exception ex) { throw new Exception(ex.Message); } return(Companies); }
public int IdGenerate() { int newid = 1; try { using var context = new BookManagementDBContext(); Report report = context.Reports.ToList().OrderByDescending(r => r.Id).FirstOrDefault(); if (report != null) { newid = ++report.Id; } } catch (Exception ex) { throw new Exception(ex.Message); } return(newid); }
public void Remove(int ReportID) { try { Report supRep = GetReportByID(ReportID); if (supRep != null) { using var context = new BookManagementDBContext(); context.Reports.Remove(supRep); context.SaveChanges(); } else { throw new Exception("The Report does not exist"); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Update(Report Report) { try { Report supRep = GetReportByID(Report.Id); if (supRep != null) { using var context = new BookManagementDBContext(); context.Reports.Update(Report); context.SaveChanges(); } else { throw new Exception("The Report does not exist."); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Remove(string ProductID) { try { Product product = GetProductByID(ProductID); if (product != null) { using var context = new BookManagementDBContext(); context.Products.Remove(product); context.SaveChanges(); } else { throw new Exception("The Product does not exist"); } } catch (Exception ex) { throw new Exception(ex.Message); } }
//public Product GetProductByUnitPrice(int UnitPrice) //{ // Product Product = null; // try // { // using var context = new BookManagementDBContext(); // Product = context.Products.SingleOrDefault(m => m.UnitPrice == UnitPrice); // } // catch (Exception ex) // { // throw new Exception(ex.Message); // } // return Product; //} //public Product GetProductByUnitInStock(int UnitsInStock) //{ // Product Product = null; // try // { // using var context = new BookManagementDBContext(); // Product = context.Products.SingleOrDefault(m => m.UnitsInStock == UnitsInStock); // } // catch (Exception ex) // { // throw new Exception(ex.Message); // } // return Product; //} public void Insert(Product Product) { try { Product product = GetProductByID(Product.ProductId); if (product == null) { using var context = new BookManagementDBContext(); context.Products.Add(Product); context.SaveChanges(); } else { throw new Exception("The Product is already exist."); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Insert(User User) { try { User user = GetUserByEmail(User.Email); if (user == null) { using var context = new BookManagementDBContext(); context.Users.Add(User); context.SaveChanges(); } else { throw new Exception("The User is already exist."); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Remove(string UserEmail) { try { User user = GetUserByEmail(UserEmail); if (user != null) { using var context = new BookManagementDBContext(); context.Users.Remove(user); context.SaveChanges(); } else { throw new Exception("The User does not exist"); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Update(Company Company) { try { Company sup = GetCompanyByID(Company.CompanyId); if (sup != null) { using var context = new BookManagementDBContext(); context.Companies.Update(Company); context.SaveChanges(); } else { throw new Exception("The Company does not exist."); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Remove(string ForAgesId) { try { Age Age = GetAgeByID(ForAgesId); if (Age != null) { using var context = new BookManagementDBContext(); context.Ages.Remove(Age); context.SaveChanges(); } else { throw new Exception("The Age does not exist"); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Remove(string CompanyID) { try { Company Company = GetCompanyByID(CompanyID); if (Company != null) { using var context = new BookManagementDBContext(); context.Companies.Remove(Company); context.SaveChanges(); } else { throw new Exception("The Company does not exist"); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Insert(Company Company) { try { Company sup = GetCompanyByID(Company.CompanyId); if (sup == null) { using var context = new BookManagementDBContext(); context.Companies.Add(Company); context.SaveChanges(); } else { throw new Exception("The Company is already exist."); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Insert(Report Report) { try { Report supRep = GetReportByID(Report.Id); if (supRep == null) { using var context = new BookManagementDBContext(); context.Reports.Add(Report); context.SaveChanges(); } else { throw new Exception("The Report is already exist."); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Insert(Age Age) { try { Age age = GetAgeByID(Age.ForAgesId); var a = GetAgeList().Where(a => a.Description.Equals(Age.Description)).FirstOrDefault(); if (age == null && a == null) { using var context = new BookManagementDBContext(); context.Ages.Add(Age); context.SaveChanges(); } else { throw new Exception("The Age is already exist."); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Insert(Category Category) { try { Category Cate = GetCategoryByID(Category.CategoryId); var cate = GetCategoryList().Where(c => c.CategoryName.Equals(Category.CategoryName)).FirstOrDefault(); if (cate == null && Cate == null) { using var context = new BookManagementDBContext(); context.Categories.Add(Category); context.SaveChanges(); } else { throw new Exception("The Category is already exist."); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public int CheckLogin(string email, string pass) { User User = null; try { using var context = new BookManagementDBContext(); User = context.Users.SingleOrDefault(m => m.Email == email && m.Password == pass); if (User != null) { return(User.RoleId); } else { return(0); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public string IdGenerate() { string newid = null; try { using var context = new BookManagementDBContext(); Company company = GetCompanyList().LastOrDefault(); if (company == null) { newid = "CM1"; } else { newid = company.CompanyId.Substring(0, 2) + (Int32.Parse(company.CompanyId.Substring(2)) + 1).ToString(); } } catch (Exception ex) { throw new Exception(ex.Message); } return(newid); }