コード例 #1
0
        public GLAccountDTO Get(int glAccountId)
        {
            GLAccount glAccount = GLAccount.GetByGLAccountID(glAccountId);

            glAccount.CurrentDTO.LoadBankAccount(glAccount);

            glAccount.CurrentDTO.BankAccount.LoadBankAccountCards(glAccount.BankAccount);
            return(glAccount.CurrentDTO);
        }
コード例 #2
0
        public bool SaveAccountDetails([FromBody] List <GLAccountDTO> data)
        {
            if (data != null && data.Count > 0)
            {
                GLEntity gLEntity = GLEntity.GetByGLEntityID(data[0].GLEntityID);

                DateTime CurrentTime = DateTime.Now;

                foreach (var account in data)
                {
                    GLAccount existingGLAccount = null;

                    if (gLEntity.GLAccounts != null && gLEntity.GLAccounts.Count > 0)
                    {
                        existingGLAccount =
                            gLEntity.GLAccounts.FirstOrDefault(x => x.GLAccountID == account.GLAccountID);
                    }

                    if (existingGLAccount == null)
                    {
                        if (account.GLAccountID > 0)
                        {
                            existingGLAccount            = GLAccount.GetByGLAccountID(account.GLAccountID);
                            existingGLAccount.GLEntityID = gLEntity.GLEntityID;
                        }
                        else
                        {
                            existingGLAccount           = GLAccount.NewGLAccount();
                            existingGLAccount.IsActive  = true;
                            existingGLAccount.CreatedBy = CurrentUserID;
                            existingGLAccount.CreatedOn = CurrentTime;
                        }

                        gLEntity.GLAccounts.Add(existingGLAccount);
                    }

                    int?        existingBankAccountID = existingGLAccount.BankAccountID;
                    BankAccount ba = null;
                    if (existingBankAccountID.HasValue && account.BankAccount == null)
                    {
                        // need to pull this as CustomCopyDTO function below will change bank account id to null
                        ba = existingGLAccount.BankAccount;
                    }

                    account.CustomCopyDTO(existingGLAccount);

                    if (!existingGLAccount.IsNew && existingGLAccount.IsDirty)
                    {
                        existingGLAccount.UpdatedBy = CurrentUserID;
                        existingGLAccount.UpdatedOn = CurrentTime;
                    }

                    if (account.BankAccount != null)
                    {
                        if (!account.BankAccountID.HasValue || account.BankAccountID < 0)
                        {
                            var bankAccount = BankAccount.NewBankAccount();
                            bankAccount.IsActive  = true;
                            bankAccount.CreatedBy = CurrentUserID;
                            bankAccount.CreatedOn = CurrentTime;
                            existingGLAccount.SetBankAccount(bankAccount);
                        }

                        if (account.BankAccount.BankAccountCards != null &&
                            account.BankAccount.BankAccountCards.Count > 0)
                        {
                            foreach (var bankCard in account.BankAccount.BankAccountCards)
                            {
                                BankAccountCard existingBankCard = null;

                                if (existingGLAccount.BankAccount.BankAccountCards != null &&
                                    existingGLAccount.BankAccount.BankAccountCards.Count > 0)
                                {
                                    existingBankCard =
                                        existingGLAccount.BankAccount.BankAccountCards.FirstOrDefault(x =>
                                                                                                      x.BankAccountCardID == bankCard.BankAccountCardID);
                                }


                                if (existingBankCard == null)
                                {
                                    existingBankCard           = BankAccountCard.NewBankAccountCard();
                                    existingBankCard.IsActive  = true;
                                    existingBankCard.CreatedBy = CurrentUserID;
                                    existingBankCard.CreatedOn = CurrentTime;
                                    existingGLAccount.BankAccount.BankAccountCards.Add(existingBankCard);
                                }

                                bankCard.CustomCopyDTO(existingBankCard);

                                if (!existingBankCard.IsNew && existingBankCard.IsDirty)
                                {
                                    existingBankCard.UpdatedBy = CurrentUserID;
                                    existingBankCard.UpdatedOn = CurrentTime;
                                }
                            }
                        }

                        account.BankAccount.CustomCopyDTO(existingGLAccount.BankAccount);

                        if (!existingGLAccount.BankAccount.IsNew &&
                            (existingGLAccount.BankAccount.IsDirty ||
                             existingGLAccount.BankAccount.IsChildDirty()))
                        {
                            existingGLAccount.IsDirty = true;
                            existingGLAccount.BankAccount.UpdatedBy = CurrentUserID;
                            existingGLAccount.BankAccount.UpdatedOn = CurrentTime;
                        }
                    }
                    else
                    {
                        if (ba != null)
                        {
                            existingGLAccount.IsDirty = true;
                            ba.IsActive  = false;
                            ba.UpdatedBy = CurrentUserID;
                            ba.UpdatedOn = CurrentTime;
                            existingGLAccount.SetBankAccount(ba, true);
                        }
                    }
                }

                if (gLEntity.IsDirty)
                {
                    gLEntity.UpdatedBy = CurrentUserID;
                    gLEntity.UpdatedOn = CurrentTime;
                }

                gLEntity.Save();

                return(true);
            }

            return(false);
        }