Exemplo n.º 1
0
        public void UpdateUsingTwoRepositories()
        {
            LocationRepository locationRepository = new LocationRepository();
            FlightRepository   flightRepository = new FlightRepository();
            Flight             flight, flightFromDb;
            Location           location;

            using (TransactionScope scope = new TransactionScope())
            {
                // Update flight and location
                flight = flightRepository.FindBy(f => f.FlightNumber == "BY001").Single();
                flight.FlightNumber = "BY001_updated";
                // Since the flight was retrieved using the current repository,
                // we don't need to call the Edit method
                flightRepository.Save();

                location      = locationRepository.FindBy(l => l.City == "Rome").Single();
                location.City = "Rome_updated";
                // Since the location was retrieved using the current repository,
                // we don't need to call the Edit method
                locationRepository.Save();

                //TODO: Lab 02, Exercise 2 Task 5.2 : Get flight to check is updated

                //TODO : Revert transaction
            }


            //TODO: Lab 02, Exercise 2 Task 5.4 : Check that update flight has been reverted

            locationRepository.Dispose();
            flightRepository.Dispose();
        }
Exemplo n.º 2
0
 void DisposeContextIfExists()
 {
     if (locationRepository != null)
     {
         context.Database.RollbackTransaction();
         locationRepository.Dispose();
     }
 }
Exemplo n.º 3
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         LocationRepository.Dispose();
     }
     base.Dispose(disposing);
 }
Exemplo n.º 4
0
 void DisposeContextIfExists()
 {
     if (userRepository != null)
     {
         context.Database.RollbackTransaction();
         userRepository?.Dispose();
         skillRepository?.Dispose();
         projectRepository?.Dispose();
         locationRepository?.Dispose();
     }
 }
Exemplo n.º 5
0
        public ActionResult EditLocation(EditLocationsViewModel model)
        {
            if (ModelState.IsValid)
            {
                LocationRepository repo     = new LocationRepository(new VIMSDBContext());
                Location           location = repo.Find((int)model.Location.Id);
                location.Name = model.Location.Name;

                repo.Context.Entry(location).State = System.Data.Entity.EntityState.Modified;
                repo.Save();
                repo.Dispose();

                return(RedirectToAction("Location"));
            }
            return(View(model.Location));
        }
Exemplo n.º 6
0
        public void UpdateUsingTwoRepositories()
        {
            LocationRepository locationRepository = new LocationRepository();
            FlightRepository   flightRepository = new FlightRepository();
            Flight             flight, flightFromDb;
            Location           location;

            using (TransactionScope scope = new TransactionScope())
            {
                // Update flight and location
                flight = flightRepository.FindBy(f => f.FlightNumber == "BY001").Single();
                flight.FlightNumber = "BY001_updated";
                // Since the flight was retrieved using the current repository,
                // we don't need to call the Edit method
                flightRepository.Save();

                location      = locationRepository.FindBy(l => l.City == "Rome").Single();
                location.City = "Rome_updated";
                // Since the location was retrieved using the current repository,
                // we don't need to call the Edit method
                locationRepository.Save();

                //TODO: Lab 02, Exercise 2 Task 5.2 : Review the query for the updated flight that is inside the transaction scope
                flightFromDb = (from f in flightRepository.GetAll()
                                where f.Source.City == "Rome_updated"
                                select f).FirstOrDefault();

                Assert.IsNotNull(flightFromDb);
                Assert.AreEqual(flightFromDb.FlightNumber, "BY001_updated");

                // Do not commit the transaction
                //scope.Complete();
            }


            //TODO: Lab 02, Exercise 2 Task 5.4 : Review the query for the updated flight that is outside the transaction scope
            flightFromDb = (from f in flightRepository.GetAll()
                            where f.Source.City == "Rome_updated"
                            select f).FirstOrDefault();

            Assert.IsNull(flightFromDb);

            locationRepository.Dispose();
            flightRepository.Dispose();
        }