예제 #1
0
 public ActionResult <ObjectResult> UpdateTower([FromBody] CondominiumInternalTower condominiumInternalTower)
 {
     try
     {
         CondominiumService condominiumService = new CondominiumService(Startup.BeePlaceDataBaseConnectionString);
         condominiumService.UpdateTower(condominiumInternalTower);
         return(StatusCode((int)HttpStatusCode.OK, condominiumInternalTower));
     }
     catch (Exception e)
     {
         return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
     }
 }
예제 #2
0
        public CondominiumInternalTower GetTower(CondominiumInternalTower condominiumInternalTower)
        {
            try
            {
                StandartPersistence standartPersistence =
                    new StandartPersistence(this.Connection);

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

                return(condominiumInternalTower);
            }
            catch (SqlException e)
            {
                throw e;
            }
        }
예제 #3
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;
                }
            }
        }
예제 #4
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;
                }
            }
        }