Пример #1
0
 public List <InvoiceDetail> GetListInvoiceDetail(int id)
 {
     using (var dataContext = new SalesManagementEntities())
     {
         return(dataContext.InvoiceDetails.Where(obj => obj.InvoiceID == id).ToList());
     }
 }
Пример #2
0
 public List <Invoice> GetList()
 {
     using (var dataContext = new SalesManagementEntities())
     {
         return(dataContext.Invoices.ToList());
     }
 }
Пример #3
0
 public List <Customer> GetList()
 {
     using (var dataContext = new SalesManagementEntities())
     {
         return(dataContext.Customers.ToList());
     }
 }
Пример #4
0
 public bool EditEmployee(Employee obj, out string serverMessage)
 {
     try
     {
         using (var dataContext = new SalesManagementEntities())
         {
             Employee objE = dataContext.Employees.Single(o => o.EmployeeID == obj.EmployeeID);
             objE.Name        = obj.Name;
             objE.BirthDate   = obj.BirthDate;
             objE.Gender      = obj.Gender;
             objE.ID          = obj.ID;
             objE.PhoneNumber = obj.PhoneNumber;
             objE.Address     = obj.Address;
             objE.JobTitle    = obj.JobTitle;
             dataContext.SaveChanges();
             serverMessage = obj.EmployeeID.ToString();
         }
         return(true);
     }
     catch (Exception ex)
     {
         serverMessage = ExceptionMessage(ex);
         return(false);
     }
 }
Пример #5
0
 public List <Employee> GetList()
 {
     using (var dataContext = new SalesManagementEntities())
     {
         return(dataContext.Employees.ToList());
     }
 }
Пример #6
0
 public bool EditProduct(Product obj, out string serverMessage)
 {
     try
     {
         using (var dataContext = new SalesManagementEntities())
         {
             Product objE = dataContext.Products.Single(o => o.ProductID == obj.ProductID);
             objE.ProductName     = obj.ProductName;
             objE.AddedDate       = obj.AddedDate;
             objE.QuantityPerUnit = obj.QuantityPerUnit;
             objE.UnitPrice       = obj.UnitPrice;
             objE.UnitsInStock    = obj.UnitsInStock;
             objE.UnitsOnInvoice  = obj.UnitsOnInvoice;
             objE.Discontinued    = obj.Discontinued;
             dataContext.SaveChanges();
             serverMessage = obj.ProductID.ToString();
         }
         return(true);
     }
     catch (Exception ex)
     {
         serverMessage = ExceptionMessage(ex);
         return(false);
     }
 }
Пример #7
0
 public List <Product> GetList()
 {
     using (var dataContext = new SalesManagementEntities())
     {
         return(dataContext.Products.ToList());
     }
 }
Пример #8
0
 public List <Product> GetSearchListProduct(string where, out bool?result)
 {
     try
     {
         using (var dataContext = new SalesManagementEntities())
         {
             string query = "Select * From Products P Where " + where;
             var    list  = dataContext.Database.SqlQuery <Product>(query).ToList();
             if (list.Count == 0)
             {
                 // không tìm ra kết quả  null rỗng
                 // trả về list rỗng
                 result = null;
                 return(new List <Product>());
             }
             else
             {
                 // tìm thành công
                 result = true;
                 return(list);
             }
         }
     }
     catch (Exception)
     {
         // lỗi trong quá trình tìm, query, database ...
         result = false;
         return(new List <Product>());
     }
 }
Пример #9
0
 public bool EditInvoice(Invoice obj, List <InvoiceDetail> listObj, out string serverMessage)
 {
     try
     {
         using (var dataContext = new SalesManagementEntities())
         {
             using (var transaction = dataContext.Database.BeginTransaction())
             {
                 try
                 {
                     Invoice objE = dataContext.Invoices.Single(o => o.InvoiceID == obj.InvoiceID);
                     objE.EmployeeID  = obj.EmployeeID;
                     objE.CustomerID  = obj.CustomerID;
                     objE.Freight     = obj.Freight;
                     objE.InvoiceDate = obj.InvoiceDate;
                     dataContext.SaveChanges();
                     var listObjE = dataContext.InvoiceDetails.Where(o => o.InvoiceID == obj.InvoiceID).ToList();
                     foreach (var objD in listObj)
                     {
                         var objDE = listObjE.Single(i => i.ProductID == objD.ProductID);
                         var prdE  = dataContext.Products.Single(o => o.ProductID == objD.ProductID);
                         if (!prdE.Discontinued)
                         {
                             int quantity = objD.Quantity - objDE.Quantity;
                             prdE.UnitsInStock   -= quantity;
                             prdE.UnitsOnInvoice += quantity;
                             objDE.Quantity       = objD.Quantity;
                             objDE.UnitPrice      = objD.UnitPrice;
                         }
                         else
                         {
                             // roll back lại nếu như sản phẩm ko còn bán nữa
                             transaction.Rollback();
                             serverMessage = "The product: " + prdE.ProductName + " has been discontinued";
                             return(false);
                         }
                         dataContext.SaveChanges();
                     }
                     transaction.Commit();
                     serverMessage = obj.InvoiceID.ToString();
                     return(true);
                 }
                 catch (Exception ex)
                 {
                     transaction.Rollback();
                     serverMessage = ExceptionMessage(ex);
                     return(false);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         serverMessage = ExceptionMessage(ex);
         return(false);
     }
 }
Пример #10
0
 public bool AddInvoice(Invoice obj, List <InvoiceDetail> listObj, out string serverMessage)
 {
     try
     {
         using (var dataContext = new SalesManagementEntities())
         {
             using (var transaction = dataContext.Database.BeginTransaction())
             {
                 try
                 {
                     dataContext.Invoices.Add(obj);
                     dataContext.SaveChanges();
                     foreach (var objD in listObj)
                     {
                         var prdE = dataContext.Products.Single(o => o.ProductID == objD.ProductID);
                         if (!prdE.Discontinued)
                         {
                             objD.InvoiceID = obj.InvoiceID;
                             dataContext.InvoiceDetails.Add(objD);
                             prdE.UnitsInStock   -= objD.Quantity;
                             prdE.UnitsOnInvoice += objD.Quantity;
                         }
                         else
                         {
                             // roll back lại nếu như sản phẩm ko còn bán nữa
                             transaction.Rollback();
                             serverMessage = "The product: " + prdE.ProductName + " has been discontinued";
                             return(false);
                         }
                         dataContext.SaveChanges();
                     }
                     transaction.Commit();
                     serverMessage = obj.InvoiceID.ToString();
                     return(true);
                 }
                 catch (Exception ex)
                 {
                     transaction.Rollback();
                     serverMessage = ExceptionMessage(ex);
                     return(false);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         serverMessage = ExceptionMessage(ex);
         return(false);
     }
 }
Пример #11
0
 public bool AddCustomer(Customer obj, out string serverMessage)
 {
     try
     {
         using (var dataContext = new SalesManagementEntities())
         {
             dataContext.Customers.Add(obj);
             dataContext.SaveChanges();
             serverMessage = obj.CustomerID.ToString();
         }
         return(true);
     }
     catch (Exception ex)
     {
         serverMessage = ExceptionMessage(ex);
         return(false);
     }
 }
Пример #12
0
 public bool DeleteCustomer(int id, out string serverMessage)
 {
     try
     {
         using (var dataContext = new SalesManagementEntities())
         {
             Customer obj = dataContext.Customers.Single(o => o.CustomerID == id);
             dataContext.Customers.Remove(obj);
             dataContext.SaveChanges();
             serverMessage = obj.CustomerID.ToString();
         }
         return(true);
     }
     catch (Exception ex)
     {
         serverMessage = ExceptionMessage(ex);
         return(false);
     }
 }
Пример #13
0
 public bool DeleteInvoice(int id, out string serverMessage)
 {
     try
     {
         using (var dataContext = new SalesManagementEntities())
         {
             using (var transaction = dataContext.Database.BeginTransaction())
             {
                 try
                 {
                     var listObj = dataContext.InvoiceDetails.Where(o => o.InvoiceID == id).ToList();
                     foreach (var objD in listObj)
                     {
                         var prdE = dataContext.Products.Single(o => o.ProductID == objD.ProductID);
                         prdE.UnitsInStock   += objD.Quantity;
                         prdE.UnitsOnInvoice -= objD.Quantity;
                         dataContext.InvoiceDetails.Remove(objD);
                         dataContext.SaveChanges();
                     }
                     Invoice obj = dataContext.Invoices.Single(o => o.InvoiceID == id);
                     dataContext.Invoices.Remove(obj);
                     dataContext.SaveChanges();
                     transaction.Commit();
                     serverMessage = obj.InvoiceID.ToString();
                     return(true);
                 }
                 catch (Exception ex)
                 {
                     transaction.Rollback();
                     serverMessage = ExceptionMessage(ex);
                     return(false);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         serverMessage = ExceptionMessage(ex);
         return(false);
     }
 }
Пример #14
0
 public bool EditCustomer(Customer obj, out string serverMessage)
 {
     try
     {
         using (var dataContext = new SalesManagementEntities())
         {
             Customer objE = dataContext.Customers.Single(o => o.CustomerID == obj.CustomerID);
             objE.Name        = obj.Name;
             objE.Gender      = obj.Gender;
             objE.PhoneNumber = obj.PhoneNumber;
             objE.Address     = obj.Address;
             objE.Email       = obj.Email;
             dataContext.SaveChanges();
             serverMessage = obj.CustomerID.ToString();
         }
         return(true);
     }
     catch (Exception ex)
     {
         serverMessage = ExceptionMessage(ex);
         return(false);
     }
 }