示例#1
0
文件: AgeDAO.cs 项目: phucvhd/pvhd1
 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);
     }
 }
示例#2
0
 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);
     }
 }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
文件: AgeDAO.cs 项目: phucvhd/pvhd1
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
        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);
        }
示例#13
0
文件: AgeDAO.cs 项目: phucvhd/pvhd1
        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);
        }
示例#14
0
        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);
        }
示例#15
0
        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);
        }
示例#16
0
 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);
     }
 }
示例#17
0
 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);
     }
 }
示例#18
0
 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);
     }
 }
示例#19
0
        //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);
            }
        }
示例#20
0
 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);
     }
 }
示例#21
0
 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);
     }
 }
示例#22
0
 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);
     }
 }
示例#23
0
文件: AgeDAO.cs 项目: phucvhd/pvhd1
 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);
     }
 }
示例#24
0
 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);
     }
 }
示例#25
0
 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);
     }
 }
示例#26
0
 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);
     }
 }
示例#27
0
文件: AgeDAO.cs 项目: phucvhd/pvhd1
 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);
     }
 }
示例#28
0
 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);
     }
 }
示例#29
0
        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);
            }
        }
示例#30
0
        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);
        }