public bool AddInvoice(Invoice invoice, List<Product> products )
        {
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    using (SalesAndInventorySystemDataContext dataContext = new SalesAndInventorySystemDataContext())
                    {
                        //Invoice newInvoice=new Invoice(){ InvoiceNo = invoice.InvoiceNo, CostPrice = invoice.CostPrice, Due = invoice.Due, InvoiceDate = invoice.InvoiceDate, TotalPrice = invoice.TotalPrice, vat = invoice.vat};
                        dataContext.Invoices.Add(invoice);
                        dataContext.SaveChanges();

                        if (invoice.InvoiceID>0)
                        {
                            foreach (Product product in products)
                            {
                                SellProduct sellProduct=new SellProduct(){ InvoiceID = invoice.InvoiceID, Price = product.Price, ProductID = product.ProductID, Quantiry = product.Quantity, Size = product.Size};
                                dataContext.SellProducts.Add(sellProduct);
                                dataContext.Database.ExecuteSqlCommand("Update Products set Quantity= Quantity-" + product.Quantity + "where ProductID="+product.ProductID);
                                dataContext.SaveChanges();
                            }
                        }
                    }
                    ts.Complete();
                    return true;
                }
                return false;
            }
            catch (Exception exception)
            {

                throw new Exception(exception.Message);
            }
        }
 public bool AddCompany(PersonType company)
 {
     try
     {
         using (SalesAndInventorySystemDataContext dataContext = new SalesAndInventorySystemDataContext())
         {
             dataContext.Companies.Add(company);
             dataContext.SaveChanges();
             return true;
         }
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
 public bool AddCategory(Category category)
 {
     try
     {
         using (SalesAndInventorySystemDataContext dataContext = new SalesAndInventorySystemDataContext())
         {
             dataContext.Categoets.Add(category);
             dataContext.SaveChanges();
             return true;
         }
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
        public bool AddProduct(Product product)
        {
            try
            {
                using (SalesAndInventorySystemDataContext dataContext = new SalesAndInventorySystemDataContext())
                {
                    dataContext.Products.Add(product);
                    dataContext.SaveChanges();
                    return true;
                }
            }
            catch (Exception exception)
            {

                throw new Exception(exception.Message);
            }
        }
 public bool DeleteCompany(PersonType company)
 {
     try
     {
         using (SalesAndInventorySystemDataContext dataContext = new SalesAndInventorySystemDataContext())
         {
             dataContext.Companies.Attach(company);
             dataContext.Entry(company).State=EntityState.Deleted;
             dataContext.SaveChanges();
             return true;
         }
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
 public bool DeleteProduct(Product product)
 {
     try
     {
         using (SalesAndInventorySystemDataContext dataContext = new SalesAndInventorySystemDataContext())
         {
             dataContext.Products.Attach(product);
             dataContext.Entry(product).State = EntityState.Deleted;
             dataContext.SaveChanges();
             return true;
         }
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
        public bool UpdateCompany(PersonType company)
        {
            try
            {
                using (SalesAndInventorySystemDataContext dataContext = new SalesAndInventorySystemDataContext())
                {
                    dataContext.Companies.Attach(company);
                    dataContext.Entry(company).State = EntityState.Modified;
                    dataContext.SaveChanges();
                    return true;

                    //_cnt.Users.Attach(user);
                    //_cnt.Entry<User>(user).Property(u => u.PasswordHash).IsModified = true;
                    //_cnt.SaveChanges();
                }
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
 public bool UpdateCategory(Category category)
 {
     try
     {
         using (SalesAndInventorySystemDataContext dataContext = new SalesAndInventorySystemDataContext())
         {
             dataContext.Categoets.Attach(category);
             dataContext.Entry(category).State = EntityState.Modified;
             dataContext.SaveChanges();
             return true;
         }
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }