public int UpdateAccountLedger(PharmaBusinessObjects.Master.AccountLedgerMaster p)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                try
                {
                    var accountLedgerMaster = context.AccountLedgerMaster.Where(q => q.AccountLedgerID == p.AccountLedgerID).FirstOrDefault();

                    if (accountLedgerMaster != null)
                    {
                        accountLedgerMaster.AccountLedgerName   = p.AccountLedgerName;
                        accountLedgerMaster.AccountLedgerCode   = p.AccountLedgerCode;
                        accountLedgerMaster.AccountLedgerTypeId = p.AccountLedgerTypeId;
                        accountLedgerMaster.AccountTypeId       = p.AccountTypeId;
                        accountLedgerMaster.CreditControlCodeID = p.CreditControlCodeID;
                        accountLedgerMaster.DebitControlCodeID  = p.DebitControlCodeID;
                        accountLedgerMaster.OpeningBalance      = p.OpeningBalance;
                        accountLedgerMaster.CreditDebit         = p.CreditDebit;
                        accountLedgerMaster.Status = p.Status;
                        accountLedgerMaster.SalePurchaseTaxType = p.SalePurchaseTaxValue;
                        accountLedgerMaster.CreatedBy           = this.LoggedInUser.Username;
                        accountLedgerMaster.CreatedOn           = System.DateTime.Now;
                    }

                    return(context.SaveChanges());
                }
                catch (DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }
        public int AddAccountLedger(PharmaBusinessObjects.Master.AccountLedgerMaster p)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                var maxAccountLedgerID = context.AccountLedgerMaster.Count() > 0 ? context.AccountLedgerMaster.Max(q => q.AccountLedgerID) + 1 : 1;

                var accountLedgerCode = "L" + maxAccountLedgerID.ToString().PadLeft(6, '0');

                AccountLedgerMaster table = new AccountLedgerMaster()
                {
                    AccountLedgerName   = p.AccountLedgerName,
                    AccountLedgerCode   = accountLedgerCode,
                    AccountLedgerTypeId = p.AccountLedgerTypeId,
                    AccountTypeId       = p.AccountTypeId,
                    OpeningBalance      = p.OpeningBalance,
                    CreditDebit         = p.CreditDebit,
                    SalePurchaseTaxType = p.SalePurchaseTaxValue,
                    Status    = p.Status,
                    CreatedBy = this.LoggedInUser.Username,
                    CreatedOn = System.DateTime.Now
                };

                var accountLedger = new Common.CommonDao().GetAccountLedgerTypes().Where(q => q.AccountLedgerTypeID == p.AccountLedgerTypeId).FirstOrDefault();

                if (accountLedger.AccountLedgerTypeSystemName != Constants.AccountLedgerType.ControlCodes)
                {
                    table.CreditControlCodeID = p.CreditControlCodeID;
                    table.DebitControlCodeID  = p.DebitControlCodeID;
                }

                context.AccountLedgerMaster.Add(table);
                return(context.SaveChanges());
            }
        }
Exemple #3
0
 internal int UpdateAccountLedger(PharmaBusinessObjects.Master.AccountLedgerMaster p)
 {
     return(new AccountLedgerMasterDao(this.LoggedInUser).UpdateAccountLedger(p));
 }