Exemple #1
0
        public void InsertTower(CondominiumInternalTower condominiumInternalTower)
        {
            using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                try
                {
                    StandartPersistence standartPersistence =
                        new StandartPersistence(this.Connection);

                    standartPersistence.Insert <CondominiumInternalTower>(condominiumInternalTower);

                    if (condominiumInternalTower.Id > 0)
                    {
                        for (int floor = 1; floor < condominiumInternalTower.FloorsQuantity; floor++)
                        {
                            for (int apto = 1; apto < condominiumInternalTower.ApartmentsQuantity; apto++)
                            {
                                var condominiumApartment = new CondominiumApartment();
                                condominiumApartment.IdCondominiumInternalTower = condominiumInternalTower.Id;
                                condominiumApartment.Floor  = floor;
                                condominiumApartment.Number = Convert.ToInt32(floor.ToString() + apto.ToString());

                                standartPersistence.Insert <CondominiumApartment>(condominiumApartment);
                            }
                        }
                    }

                    transactionScope.Complete();
                }
                catch (SqlException e)
                {
                    throw e;
                }
                catch (TransactionException e)
                {
                    throw e;
                }
            }
        }
Exemple #2
0
        public void UpdateTower(CondominiumInternalTower condominiumInternalTower)
        {
            using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                try
                {
                    StandartPersistence standartPersistence =
                        new StandartPersistence(this.Connection);

                    var existCondominiumInternalTower = standartPersistence.GetEntities <CondominiumInternalTower>(CommandType.Text,
                                                                                                                   "SELECT * FROM CondominiumInternalTower WHERE Id = @IdTower",
                                                                                                                   new { IdTower = condominiumInternalTower.Id }).SingleOrDefault();

                    if (existCondominiumInternalTower.FloorsQuantity > condominiumInternalTower.FloorsQuantity)
                    {
                        int floors = existCondominiumInternalTower.FloorsQuantity - condominiumInternalTower.FloorsQuantity;

                        for (int floor = 1; floor < floors; floor++)
                        {
                            for (int apto = 1; apto < condominiumInternalTower.ApartmentsQuantity; apto++)
                            {
                                var condominiumApartment = new CondominiumApartment();
                                condominiumApartment.IdCondominiumInternalTower = condominiumInternalTower.Id;
                                condominiumApartment.Floor  = floor;
                                condominiumApartment.Number = Convert.ToInt32(floor.ToString() + apto.ToString());

                                standartPersistence.Insert <CondominiumApartment>(condominiumApartment);
                            }
                        }
                    }
                    else if (existCondominiumInternalTower.FloorsQuantity < condominiumInternalTower.FloorsQuantity)
                    {
                        int floors = condominiumInternalTower.FloorsQuantity - existCondominiumInternalTower.FloorsQuantity;

                        for (int floor = 1; floor < floors; floor++)
                        {
                            for (int apto = 1; apto < condominiumInternalTower.ApartmentsQuantity; apto++)
                            {
                                var condominiumApartment = new CondominiumApartment();
                                condominiumApartment.IdCondominiumInternalTower = condominiumInternalTower.Id;
                                condominiumApartment.Floor  = floor;
                                condominiumApartment.Number = Convert.ToInt32(floor.ToString() + apto.ToString());

                                standartPersistence.Delete <CondominiumApartment>(condominiumApartment);
                            }
                        }
                    }

                    standartPersistence.Update <CondominiumInternalTower>(condominiumInternalTower);

                    transactionScope.Complete();
                }
                catch (SqlException e)
                {
                    throw e;
                }
                catch (TransactionException e)
                {
                    throw e;
                }
            }
        }