Example #1
0
        /// <summary>
        /// It update a customer and, eventually, all the added or updated animals and treatments related
        /// </summary>
        /// <param name="obj2Upd"></param>
        /// <returns></returns>
        public bool UpdateCustomerFull(Customer obj2Upd)
        {
            CustomerDAL    custDal     = new CustomerDAL();
            bool           Bret        = true;
            SqlConnection  connessione = new SqlConnection(CommonData.connectionString);
            SqlTransaction oTrans      = null;

            try
            {
                connessione.Open();
                oTrans = connessione.BeginTransaction();
                if (obj2Upd.CurrentState != ObjectState.view)
                {
                    Bret = UpdateCustomer(obj2Upd, connessione, oTrans);
                }
                //If the customers has a list of animals, even if unchanged, i pass this list to the function how is dealing, because they could have treatments changed
                if (obj2Upd.animals != null && obj2Upd.animals.Count > 0)
                {
                    AnimalDAL animalDal = new AnimalDAL();
                    Bret = Bret & animalDal.UpdateAnimalList(obj2Upd.animals, obj2Upd, connessione, oTrans);
                }
                if (Bret)
                {
                    oTrans.Commit();
                }
                else
                {
                    oTrans.Rollback();
                }
                return(Bret);
            }
            catch (Exception ex)
            {
                if (oTrans != null)
                {
                    oTrans.Rollback();
                }
                throw ex;
            }
            finally
            {
                connessione.Close();
            }
        }
Example #2
0
        /// <summary>
        /// It inserts a new customer and, eventually, all the added animals and treatments related
        /// </summary>
        /// <param name="obj2Add">the customer to be added</param>
        /// <returns></returns>
        public bool InsertCustomerFull(Customer obj2Add)
        {
            CustomerDAL    custDal     = new CustomerDAL();
            bool           Bret        = true;
            SqlConnection  connessione = new SqlConnection(CommonData.connectionString);
            SqlTransaction oTrans      = null;

            try
            {
                connessione.ConnectionString = CommonData.connectionString;
                connessione.Open();
                oTrans = connessione.BeginTransaction();
                Bret   = custDal.InsertCustomer(obj2Add, connessione, oTrans);
                //If the new customers has a list of animals added simultaneously i pass this list to the function how is dealing
                if (obj2Add.animals != null && obj2Add.animals.Count > 0)
                {
                    AnimalDAL animalDal = new AnimalDAL();
                    Bret = Bret & animalDal.UpdateAnimalList(obj2Add.animals, obj2Add, connessione, oTrans);
                }
                if (Bret)
                {
                    oTrans.Commit();
                }
                else
                {
                    oTrans.Rollback();
                }
                return(Bret);
            }
            catch (Exception ex)
            {
                if (oTrans != null)
                {
                    oTrans.Rollback();
                }
                throw ex;
            }
            finally
            {
                connessione.Close();
            }
        }