public static void TestFixtureSetup(TestContext context)
        {
            con = new NpgsqlConnection(cs);
            con.Open();

            ownersRepository = new OwnersRepository(con);
        }
Example #2
0
 public IHttpActionResult Get(bool includes)
 {
     using (var repository = new OwnersRepository())
     {
         return(Ok(repository.GetCollection(includes)));
     }
 }
Example #3
0
        // Business Logic pass through code to Select an Owner by ID
        public OwnersEntity SelectOwnerById(int id)
        {
            try
            {
                OwnersEntity returnedEntity;
                using (var repository = new OwnersRepository())
                {
                    returnedEntity = repository.SelectById(id);
                    if (returnedEntity != null)
                    {
                        // Business Calculation function called from here
                        returnedEntity.PetYears = GetPetYears(returnedEntity.PetAge);
                    }
                }

                return(returnedEntity);
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                throw new Exception("BusinessLogic:OwnersBusiness::SelectOwnerById::Error occured.", ex);
            }
        }
Example #4
0
        // Business Logic pass through code to Select all Owners
        public List <OwnersEntity> SelectAllOwners()
        {
            var returnedEntities = new List <OwnersEntity>();

            try
            {
                using (var repository = new OwnersRepository())
                {
                    // HERE A CALCULATION CAN BE ADDED AS A COLUMN IN SelectAll function
                    foreach (var entity in repository.SelectAll())
                    {
                        entity.PetYears = GetPetYears(entity.PetAge);
                        returnedEntities.Add(entity);
                    }
                }

                return(returnedEntities);
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                throw new Exception("BusinessLogic:OwnersBusiness::SelectAllOwners::Error occured.", ex);
            }
        }
        public static void TestFixtureSetup(TestContext context)
        {
            con = new NpgsqlConnection(cs);
            con.Open();

            regionsRepository       = new RegionsRepository(con);
            countriesRepository     = new CountriesRepository(con);
            manufacturersRepository = new ManufacturersRepository(con);
            carsRepository          = new CarsRepository(con);
            carValidation           = new CarValidation(con);
            ownerCarsRepository     = new OwnerCarsRepository(con);
            ownersRepository        = new OwnersRepository(con);

            regionsRepository.Save(Region1);
            regionsRepository.Save(Region2);
            regionsRepository.Save(Region3);
            regionsRepository.Flush();

            countriesRepository.Save(Country1);
            countriesRepository.Save(Country2);
            countriesRepository.Save(Country3);
            countriesRepository.Save(Country4);
            countriesRepository.Save(Country5);
            countriesRepository.Flush();

            manufacturersRepository.Save(Manufacturer1);
            manufacturersRepository.Save(Manufacturer2);
            manufacturersRepository.Save(Manufacturer3);
            manufacturersRepository.Save(Manufacturer4);
            manufacturersRepository.Save(Manufacturer5);
            manufacturersRepository.Save(Manufacturer6);
            manufacturersRepository.Save(Manufacturer7);
            manufacturersRepository.Save(Manufacturer8);
            manufacturersRepository.Save(Manufacturer9);
            manufacturersRepository.Flush();

            carsRepository.Save(Car1);
            carsRepository.Save(Car2);
            carsRepository.Save(Car3);
            carsRepository.Save(Car4);
            carsRepository.Save(Car5);
            carsRepository.Save(Car6);
            carsRepository.Save(Car7);
            carsRepository.Save(Car8);
            carsRepository.Save(Car9);
            carsRepository.Save(Car10);
            carsRepository.Save(Car11);
            carsRepository.Save(Car12);
            carsRepository.Save(Car13);
            carsRepository.Save(Car14);
            carsRepository.Save(Car15);
            carsRepository.Flush();

            ownersRepository.SaveAndFlush(Owner2);

            ownerCarsRepository.SaveAndFlush(OwnerCar2);
        }
Example #6
0
        public IHttpActionResult DeleteAllData()
        {
            using (var repository = new OwnersRepository())
            {
                repository.DeleteAll();
            }

            return(Ok("Database cleared"));
        }
Example #7
0
        public void GetAll_WhenInvoked_ReturnsAllOwnersWithPets()
        {
            var petsContext = new PetsContext
            {
                Owners = new List <Owner>
                {
                    new Owner
                    {
                        Name   = "Bob",
                        Gender = "Male",
                        Age    = 23,
                        Pets   = new List <Pet>
                        {
                            new Pet
                            {
                                Name = "Garfield",
                                Type = "Cat"
                            },
                            new Pet
                            {
                                Name = "Fido",
                                Type = "Dog"
                            }
                        }
                    },
                    new Owner
                    {
                        Name   = "Jennifer",
                        Gender = "Female",
                        Age    = 18,
                        Pets   = new List <Pet>
                        {
                            new Pet
                            {
                                Name = "Garfield",
                                Type = "Cat"
                            }
                        }
                    },
                    new Owner
                    {
                        Name   = "Fred",
                        Gender = "Male",
                        Age    = 40,
                        Pets   = null
                    }
                }
            };

            var repository = new OwnersRepository(new LoggerFactory(), petsContext);

            var result = repository.GetAll();

            Assert.Equal(3, result.Count());
            Assert.Equal(3, result.Where(o => o.Pets != null).SelectMany(x => x.Pets).Count());
        }
Example #8
0
 public UnitOfWork(VehiclesPriceListAppContext context)
 {
     _context              = context;
     VehiclesPriceList     = new VehiclesPriceListRepository(_context);
     Menufacturers         = new MenufacturersRepository(_context);
     MenufactureringOrigin = new MenufactureringOriginRepository(_context);
     VehicleOwners         = new OwnersRepository(_context);
     VehicleStatus         = new StatusRepository(_context);
     VehicleType           = new TypeRepository(_context);
 }
Example #9
0
        public static void TestFixtureSetup(TestContext context)
        {
            con = new NpgsqlConnection(cs);
            con.Open();

            ownersRepository = new OwnersRepository(con);
            ownersService    = new OwnersService(con);

            ownersRepository.Save(Owner1);
            ownersRepository.Save(Owner2);
            ownersRepository.Save(Owner3);
            ownersRepository.Flush();
        }
Example #10
0
        public IHttpActionResult SeedData()
        {
            var owners = dataProvider.GetSampleData();

            using (var repository = new OwnersRepository())
            {
                foreach (var owner in owners)
                {
                    repository.Create(owner);
                }
            }

            return(Ok("Data seeded"));
        }
Example #11
0
        // Business Logic pass through code to Delete an Owner by ID
        public bool DeleteOwnerById(int id)
        {
            try
            {
                using (var repository = new OwnersRepository())
                {
                    return(repository.DeleteById(id));
                }
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                throw new Exception("BusinessLogic:OwnersBusiness::DeleteOwnerById::Error occured.", ex);
            }
        }
Example #12
0
        public IHttpActionResult GetById(int id, bool includes)
        {
            Owner owner = null;

            using (var repository = new OwnersRepository())
            {
                owner = repository.GetById(id, includes);
            }

            if (owner != null)
            {
                return(Ok(owner));
            }
            else
            {
                return(NotFound());
            }
        }
Example #13
0
        // Business Logic pass through code to Update Owner
        public bool UpdateOwner(OwnersEntity entity)
        {
            try
            {
                bool bOpDoneSuccessfully;
                using (var repository = new OwnersRepository())
                {
                    bOpDoneSuccessfully = repository.Update(entity);
                }

                return(bOpDoneSuccessfully);
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                throw new Exception("BusinessLogic:OwnersBusiness::UpdateOwner::Error occured.", ex);
            }
        }
 /// <summary>Initializes a new instance of the <see cref="OwnerCarValidation"/> class.</summary>
 /// <param name="npgsqlConnection">The NPGSQL connection.</param>
 public OwnerCarValidation(NpgsqlConnection npgsqlConnection) : base(npgsqlConnection)
 {
     ownersRepository    = new OwnersRepository(npgsqlConnection);
     carsRepository      = new CarsRepository(npgsqlConnection);
     ownerCarsRepository = new OwnerCarsRepository(npgsqlConnection);
 }