Ejemplo n.º 1
0
        public bool Save <T>(T item) where T : IContract
        {
            var result = 0;

            var branch = (Branch)(object)item;

            if (currentTransaction == null)
            {
                connection = db.CreateConnection();
                connection.Open();
            }

            var transaction = (currentTransaction == null ? connection.BeginTransaction() : currentTransaction);


            try
            {
                var savecommand = db.GetStoredProcCommand(DBRoutine.SAVEBRANCH);

                db.AddInParameter(savecommand, "BranchID", System.Data.DbType.Int16, branch.BranchID);
                db.AddInParameter(savecommand, "BranchCode", System.Data.DbType.String, branch.BranchCode);
                db.AddInParameter(savecommand, "BranchName", System.Data.DbType.String, branch.BranchName);
                db.AddInParameter(savecommand, "RegNo", System.Data.DbType.String, branch.RegNo);
                db.AddInParameter(savecommand, "IsActive", System.Data.DbType.Boolean, branch.IsActive);
                db.AddInParameter(savecommand, "CompanyCode", System.Data.DbType.String, branch.CompanyCode);

                db.AddInParameter(savecommand, "CreatedBy", System.Data.DbType.String, branch.CreatedBy);
                db.AddInParameter(savecommand, "ModifiedBy", System.Data.DbType.String, branch.ModifiedBy);


                result = db.ExecuteNonQuery(savecommand, transaction);
                if (result > 0)
                {
                    AddressDAL addressDAL = new AddressDAL();
                    branch.BranchAddress.CreatedBy     = branch.CreatedBy;
                    branch.BranchAddress.ModifiedBy    = branch.ModifiedBy;
                    branch.BranchAddress.AddressLinkID = branch.BranchCode;
                    result = addressDAL.Save(branch.BranchAddress, transaction) == true ? 1 : 0;
                }
                if (result > 0)
                {
                    transaction.Commit();
                }
                else
                {
                    transaction.Rollback();
                }
            }
            catch (Exception)
            {
                transaction.Rollback();

                throw;
            }

            return(result > 0 ? true : false);
        }
Ejemplo n.º 2
0
        public Address GetCompanyAddress(Company companyItem)
        {
            var contactItem = new Address
            {
                AddressLinkID = companyItem.CompanyCode,
                AddressType   = "Company"
            };

            var currentAddress = new AddressDAL().GetContactsByCustomer(contactItem).FirstOrDefault();


            //companyItem.ContactItem =  new ContactDAL().GetItem(contactItem);

            return(currentAddress);
        }
Ejemplo n.º 3
0
        public bool Save <T>(T item) where T : IContract
        {
            var result = 0;

            var company = (Company)(object)item;

            if (currentTransaction == null)
            {
                connection = db.CreateConnection();
                connection.Open();
            }

            var transaction = (currentTransaction == null ? connection.BeginTransaction() : currentTransaction);


            try
            {
                var savecommand = db.GetStoredProcCommand(DBRoutine.SAVECOMPANY);

                db.AddInParameter(savecommand, "CompanyCode", System.Data.DbType.String, company.CompanyCode);
                db.AddInParameter(savecommand, "CompanyName", System.Data.DbType.String, company.CompanyName);
                db.AddInParameter(savecommand, "RegNo", System.Data.DbType.String, company.RegNo);
                //db.AddInParameter(savecommand, "Logo", System.Data.DbType.Object, company.Logo);
                db.AddInParameter(savecommand, "IsActive", System.Data.DbType.Boolean, company.IsActive);
                db.AddInParameter(savecommand, "CreatedBy", System.Data.DbType.String, company.CreatedBy);
                db.AddInParameter(savecommand, "ModifiedBy", System.Data.DbType.String, company.ModifiedBy);



                result = db.ExecuteNonQuery(savecommand, transaction);

                if (result > 0)
                {
                    AddressDAL addressDAL = new AddressDAL();
                    company.CompanyAddress.CreatedBy     = company.CreatedBy;
                    company.CompanyAddress.ModifiedBy    = company.ModifiedBy;
                    company.CompanyAddress.AddressLinkID = company.CompanyCode;
                    result = addressDAL.Save(company.CompanyAddress, transaction) == true ? 1 : 0;
                }



                if (result > 0)
                {
                    if (currentTransaction == null)
                    {
                        transaction.Commit();
                    }
                }
                else
                {
                    if (currentTransaction == null)
                    {
                        transaction.Rollback();
                    }
                }
            }
            catch (Exception ex)
            {
                if (currentTransaction == null)
                {
                    transaction.Rollback();
                }

                throw ex;
            }

            return(result > 0 ? true : false);
        }