Esempio n. 1
0
        public Returner Create()
        {
            if (db.Products.Any(p => p.ProductName == this.ProductName))
            {
                return(new Returner
                {
                    Message = Message.Product_Name_Already_Exist
                });
            }
            var Cat = db.ProductCategories.Where(p => p.Id == this.Category).SingleOrDefault();

            if (Cat != null)
            {
                AccountingTree ProjectNode = new AccountingTree();
                ProjectNode.NodeName = this.ProductName;
                ProjectNode.Parent   = Cat.AccTreeCode;
                db.AccountingTrees.Add(ProjectNode);
                db.SaveChanges();
            }
            var AccID = db.AccountingTrees.Where(p => p.NodeName == this.ProductName && p.Parent == Cat.AccTreeCode).SingleOrDefault();

            this.AccountID = AccID.Id;
            db.Products.Add(this);
            db.SaveChanges();
            new Stock
            {
                ProductID = this.Id
            }.NewProduct();
            return(new Returner
            {
                Message = Message.Product_Created_Successfully
            });
        }
 public bool UpdateTree(List <TreeNode> _Tree, TreeNode Parent = null)
 {
     foreach (TreeNode node in _Tree)
     {
         AccountingTree CurrentNode = db.AccountingTrees.Where(p => p.Id == node.id).FirstOrDefault();
         if (CurrentNode == null)
         {
             CurrentNode = new AccountingTree();
             db.AccountingTrees.Add(CurrentNode);
         }
         CurrentNode.NodeName = node.name;
         if (Parent != null)
         {
             CurrentNode.Parent = Parent.id;
         }
         else
         {
             CurrentNode.Parent = null;
         }
         db.SaveChanges();
         if (node.children.Any())
         {
             UpdateTree(node.children, node);
         }
     }
     return(true);
 }
Esempio n. 3
0
        public Returner Add()
        {
            var ParentAccount = db.AccountingTrees.Where(p => p.KeyAccountID == (int)KeyAccounts.Projects).FirstOrDefault();

            if (ParentAccount != null)
            {
                AccountingTree ProjectNode = new AccountingTree();
                ProjectNode.NodeName = this.ProjectName;
                ProjectNode.Parent   = ParentAccount.Id;
                db.AccountingTrees.Add(ProjectNode);
                db.SaveChanges();
            }
            var AccID = db.AccountingTrees.Where(p => p.NodeName == this.ProjectName && p.Parent == ParentAccount.Id).SingleOrDefault();

            this.AccountID = AccID.Id;
            db.Projects.Add(this);
            db.SaveChanges();
            new Stock
            {
                ProjectID = this.Id
            }.NewProject();
            return(new Returner
            {
                Message = Message.Project_Created_Successfully
            });
        }
        public int AddCustomerNode()
        {
            int            ParentID = db.AccountingTrees.Where(p => p.KeyAccountID == (int)KeyAccounts.Customers).SingleOrDefault().Id;
            AccountingTree Node     = new AccountingTree();

            Node.NodeName = this.Name;
            Node.Parent   = ParentID;
            db.AccountingTrees.Add(Node);
            db.SaveChanges();
            return(Node.Id);
        }
Esempio n. 5
0
        private int AddSupplierAccountingTree()
        {
            int            ParentSupplierID = db.AccountingTrees.Where(p => p.KeyAccountID == (int)KeyAccounts.Suppliers).SingleOrDefault().Id;
            AccountingTree SupplierNode     = new AccountingTree();

            SupplierNode.NodeName = this.Name;
            SupplierNode.Parent   = ParentSupplierID;
            db.AccountingTrees.Add(SupplierNode);
            db.SaveChanges();
            return(SupplierNode.Id);
        }
Esempio n. 6
0
        private int CreateUnitNode()
        {
            int            ProjectAccID = (int)(db.Projects.Where(p => p.Id == this.ProjectID).SingleOrDefault().AccountID);
            int            ParentNode   = db.AccountingTrees.Where(p => p.Id == ProjectAccID).SingleOrDefault().Id;
            AccountingTree UnitNode     = new AccountingTree();

            UnitNode.NodeName = Enum.GetName(typeof(UnitTypes), this.UnitType);
            UnitNode.Parent   = ParentNode;
            db.AccountingTrees.Add(UnitNode);
            db.SaveChanges();
            return(UnitNode.Id);
        }
        public bool deleteNode(int id)
        {
            AccountingTree node = db.AccountingTrees.Where(p => p.Id == id).FirstOrDefault();

            if (node != null)
            {
                foreach (AccountingTree child in node.AccountingTree1)
                {
                    db.AccountingTrees.Remove(child);
                }
                db.SaveChanges();
                db.AccountingTrees.Remove(node);
                db.SaveChanges();
            }
            return(true);
        }
Esempio n. 8
0
        public Returner Edit()
        {
            var  ProdToEdit    = db.Products.Where(p => p.Id == this.Id).SingleOrDefault();
            bool CatNotChanged = (ProdToEdit.Category == this.Category);
            int  NewParent;
            var  AccToEdit = db.AccountingTrees.Where(p => p.Id == ProdToEdit.AccountID).SingleOrDefault();

            if (CatNotChanged)
            {
                AccToEdit.NodeName = this.ProductName;
                db.SaveChanges();
                NewParent = (int)AccToEdit.Parent;
            }
            else
            {
                db.AccountingTrees.Remove(AccToEdit);
                db.SaveChanges();
                var Cat = db.ProductCategories.Where(p => p.Id == this.Category).SingleOrDefault();
                if (Cat != null)
                {
                    AccountingTree ProjectNode = new AccountingTree();
                    ProjectNode.NodeName = this.ProductName;
                    ProjectNode.Parent   = Cat.AccTreeCode;
                    db.AccountingTrees.Add(ProjectNode);
                    db.SaveChanges();
                }
                NewParent = (int)Cat.AccTreeCode;
            }
            var AccID = db.AccountingTrees.Where(p => p.NodeName == this.ProductName && p.Parent == NewParent).SingleOrDefault();

            ProdToEdit.AccountID    = AccID.Id;
            ProdToEdit.Category     = this.Category;
            ProdToEdit.Description  = this.Description;
            ProdToEdit.ProductName  = this.ProductName;
            ProdToEdit.PtoSRate     = this.PtoSRate;
            ProdToEdit.PurchaseUnit = this.PurchaseUnit;
            ProdToEdit.SalesUnit    = this.SalesUnit;
            db.SaveChanges();
            return(new Returner
            {
                Message = Message.Product_Update_Successfully
            });
        }
        private void EditEmployerAccountingTrees(string EmployerName, List <int> LON)
        {
            int NEmpAccID     = LON[0];
            int NImprestAccID = LON[1];
            int NBenifitAccID = LON[2];
            int NPenaltyAccID = LON[3];
            //Get Accounting Trees Objects To Update
            AccountingTree EmpNode     = db.AccountingTrees.Where(p => p.Id == NEmpAccID).SingleOrDefault();
            AccountingTree ImprestNode = db.AccountingTrees.Where(p => p.Id == NImprestAccID).SingleOrDefault();
            AccountingTree BenifitNode = db.AccountingTrees.Where(p => p.Id == NBenifitAccID).SingleOrDefault();
            AccountingTree PenaltyNode = db.AccountingTrees.Where(p => p.Id == NPenaltyAccID).SingleOrDefault();

            //Update Object Properties
            EmpNode.NodeName     = EmployerName;
            ImprestNode.NodeName = EmployerName;
            BenifitNode.NodeName = EmployerName;
            PenaltyNode.NodeName = EmployerName;
            //Save Changes To DB
            db.SaveChanges();
        }
        private List <int> AddEmployerAccountingTrees(string EmployerName)
        {
            //Get Parents IDs
            int ParentOfEmpAccID     = db.AccountingTrees.Where(p => p.KeyAccountID == (int)KeyAccounts.Employee).SingleOrDefault().Id;
            int ParentOfImprestAccID = db.AccountingTrees.Where(p => p.KeyAccountID == (int)KeyAccounts.Imprestes).SingleOrDefault().Id;
            int ParentOfBenifitAccID = db.AccountingTrees.Where(P => P.KeyAccountID == (int)KeyAccounts.Benifits).SingleOrDefault().Id;
            int ParentOfPenaltyAccID = db.AccountingTrees.Where(p => p.KeyAccountID == (int)KeyAccounts.Others).SingleOrDefault().Id;
            //Define Accounting Trees Objects To Save To DB
            AccountingTree EmpNode     = new AccountingTree();
            AccountingTree ImprestNode = new AccountingTree();
            AccountingTree BenifitNode = new AccountingTree();
            AccountingTree PenaltyNode = new AccountingTree();

            //Fill Object Properties
            EmpNode.NodeName     = EmployerName;
            EmpNode.Parent       = ParentOfEmpAccID;
            ImprestNode.NodeName = EmployerName;
            ImprestNode.Parent   = ParentOfImprestAccID;
            BenifitNode.NodeName = EmployerName;
            BenifitNode.Parent   = ParentOfBenifitAccID;
            PenaltyNode.NodeName = EmployerName;
            PenaltyNode.Parent   = ParentOfPenaltyAccID;
            //Add Objects To Context
            db.AccountingTrees.Add(EmpNode);
            db.AccountingTrees.Add(ImprestNode);
            db.AccountingTrees.Add(BenifitNode);
            db.AccountingTrees.Add(PenaltyNode);
            //Save Changes To DB
            db.SaveChanges();
            //Fill List Of Int With Saved Nodes IDs
            List <int> LON = new List <int>();

            LON.Add(EmpNode.Id);
            LON.Add(ImprestNode.Id);
            LON.Add(BenifitNode.Id);
            LON.Add(PenaltyNode.Id);
            //Return List Of Nodes IDs
            return(LON);
        }
        private List <FinancialTransaction> GetFtChilds(AccountingTree Acc, int ToAcc)
        {
            List <FinancialTransaction> LOFTTT = new List <FinancialTransaction>();

            if (ToAcc == 0)
            {
                LOFTTT = Acc.FinancialTransactions.ToList();
                LOFTTT.AddRange(Acc.FinancialTransactions1);
            }
            else
            {
                LOFTTT = Acc.FinancialTransactions.Where(p => p.FromAccount == ToAcc).ToList();
                LOFTTT.AddRange(Acc.FinancialTransactions1.Where(p => p.FromAccount == ToAcc));
            }
            if (Acc.AccountingTree1.Count > 0)
            {
                foreach (AccountingTree Child in Acc.AccountingTree1)
                {
                    LOFTTT.AddRange(GetFtChilds(Child, ToAcc));
                }
            }
            return(LOFTTT.OrderBy(p => p.Id).ToList());
        }