/// <summary>
        /// Enregistre ou met a jour un evenement
        /// </summary>
        public void Save()
        {
            if (this.Id == Guid.Empty)
            {
                this.Metier.Id = Guid.NewGuid();
                this.Metier.ImageEvenement.Id   = Guid.NewGuid();
                this.Metier.AdresseEvenement.Id = Guid.NewGuid();

                using (ParkingContext context = new ParkingContext())
                {
                    ServiceAdresse.Insert(this.Metier.AdresseEvenement, context);
                    ServiceImage.Insert(this.Metier.ImageEvenement, context);

                    string query = "https://maps.googleapis.com/maps/api/geocode/json?address=" + this.Metier.AdresseEvenement.ToString() + "&key=AIzaSyCyoqbqJVd_MtZRT_0DmYmznxxJWRfMjQI";

                    using (WebClient wc = new WebClient())
                    {
                        var json = wc.DownloadString(query);
                        RootObjectGoogle item = JsonConvert.DeserializeObject <RootObjectGoogle>(json);
                        if (item != null)
                        {
                            this.Metier.AdresseEvenement.lat = item.results.FirstOrDefault().geometry.location.lat;
                            this.Metier.AdresseEvenement.lng = item.results.FirstOrDefault().geometry.location.lng;
                        }
                    }

                    ServiceEvenement.Insert(this.Metier, context);
                    context.SaveChanges();
                }
            }
            else
            {
                ServiceEvenement.Update(this.Metier);
            }
        }
Exemple #2
0
 private bool IsCarKnown(string licensePlate)
 {
     using (var context = new ParkingContext())
     {
         return(context.Customers.Any(c => c.LicensePlate == licensePlate));
     }
 }
Exemple #3
0
        /// <summary>
        /// Ne pas utiliser en cours d'ecriture
        /// </summary>
        /// <param name="adresse"></param>
        /// <returns></returns>
        public static List <Parking> Get3(Guid eventID)
        {
            List <Parking> listParking         = new List <Parking>();
            List <Parking> listParkingtoReturn = new List <Parking>();
            Evenement      evenement           = new Evenement();

            using (ParkingContext context = new ParkingContext())
            {
                listParking = context.Parkings.Include("AdressePark").Where(p => p.NBPlaceLibre > 0).ToList();
                evenement   = context.Evenements.Include("AdresseEvenement").Where(e => e.Id == eventID).FirstOrDefault();
            }

            Parking closestPark     = new Parking();
            double  closestDistance = double.MaxValue;

            for (int i = 0; i < listParking.Count(); i++)
            {
                Parking parking  = listParking[i];
                double  distance = closestAddress((double)evenement.AdresseEvenement.lng, (double)evenement.AdresseEvenement.lat, parking);

                parking.Distance    = distance;
                parking.TarifEstime = CalculTarif(evenement.Duree);
                listParkingtoReturn.Add(parking); // a Modifier pour ne prendre que les 3 plus proches
            }
            var o = listParkingtoReturn.OrderBy(p => p.Distance).Take(3).ToList();

            return(listParkingtoReturn.OrderBy(p => p.Distance).Take(3).ToList());
        }
Exemple #4
0
 private bool IsCarInPark(string licensePlate)
 {
     using (var context = new ParkingContext())
     {
         return(context.Customers.Where(c => c.LicensePlate == licensePlate).Any(c => c.IsInCarPark));
     }
 }
        public void GetAllTest()
        {
            var options = new DbContextOptionsBuilder <ParkingContext>()
                          .UseInMemoryDatabase(databaseName: "ParkingContext")
                          .Options;

            // Insert seed data into the database using one instance of the context
            using (var context = new ParkingContext(options))
            {
                context.Cars.Add(new Car {
                    RegNo = "B-11-BB"
                });
                context.Cars.Add(new Car {
                    RegNo = "B-11-AA"
                });
                context.Cars.Add(new Car {
                    RegNo = "B-11-CC"
                });
                context.SaveChanges();
            }

            // Use a clean instance of the context to run the test
            using (var context = new ParkingContext(options))
            {
                Assert.AreEqual(3, context.Cars.Count());
            }
        }
Exemple #6
0
 private bool IsLongTermParker(string licensePlate)
 {
     using (var context = new ParkingContext())
     {
         return(context.Customers.Find(licensePlate).IsLongTimeParker);
     }
 }
Exemple #7
0
        public ParkingSpotControllerTests()
        {
            //setup test database
            ServiceProvider serviceProvider = new ServiceCollection()
                                              .AddEntityFrameworkSqlServer()
                                              .BuildServiceProvider();

            DbContextOptionsBuilder builder = new DbContextOptionsBuilder <ParkingContext>();

            builder.UseSqlServer($"Server=localhost;Database=ParkingTestDb_{Guid.NewGuid()};Trusted_Connection=True;MultipleActiveResultSets=true")
            .UseInternalServiceProvider(serviceProvider);

            context = new ParkingContext(builder.Options);
            context.Database.Migrate();

            //mock controller
            ParkingSpotManager         parkingSpotRepo = new ParkingSpotManager();
            ReservationTimeSlotManager timeSlotRepo    = new ReservationTimeSlotManager();

            controller = new ParkingSpotsController(parkingSpotRepo, timeSlotRepo, context);

            //mock http requests
            var claim       = new Claim("accountID", "testID");
            var httpContext = new Mock <HttpContext>();

            httpContext.Setup(m => m.User.IsInRole("admin")).Returns(true);
            httpContext.Setup(m => m.User.FindFirst(ClaimTypes.NameIdentifier)).Returns(claim);

            var controllerContext = new ControllerContext(new ActionContext(httpContext.Object, new RouteData(), new ControllerActionDescriptor()));

            controller.ControllerContext = controllerContext;
        }
Exemple #8
0
 private int CalculateAvailableShortTermParkingLots()
 {
     using (var context = new ParkingContext())
     {
         return(maxShortTermCars - CalculateCarsOfShortTermParkersInCarPark());
     }
 }
Exemple #9
0
 private int CalculateCarsOfShortTermParkersInCarPark()
 {
     using (var context = new ParkingContext())
     {
         return(context.Customers.Where(c => c.IsInCarPark == true && c.IsLongTimeParker == false).Count());
     }
 }
Exemple #10
0
 private Customer GetCustomer(string licensePlate)
 {
     using (var context = new ParkingContext())
     {
         return(context.Customers.Where(c => c.LicensePlate == licensePlate).Single());
     }
 }
Exemple #11
0
 private int CalculateCarsInCarParkOverall()
 {
     using (var context = new ParkingContext())
     {
         return(context.Customers.Where(c => c.IsInCarPark == true).Count());
     }
 }
Exemple #12
0
        static void Seed(ParkingContext db)
        {
            var tickets = new List <Ticket> {
                //ReleaseDate = new DateTime(2017, 03, 24),
                new Ticket {
                    valorCobrado = 15, especial = false, dataHoraEmissao = DateTime.Now.AddMinutes(-18), dataHoraValidade = DateTime.Now.AddMinutes(-3)
                },
                new Ticket {
                    valorCobrado = 20, especial = false, dataHoraEmissao = DateTime.Now.AddDays(-1), dataHoraValidade = DateTime.Now.AddMinutes(15).AddDays(-1)
                },
                new Ticket {
                    valorCobrado = 10, especial = false, dataHoraEmissao = DateTime.Now.AddHours(-3), dataHoraValidade = DateTime.Now.AddMinutes(15).AddHours(-3)
                },
                new Ticket {
                    valorCobrado = 5, especial = false, dataHoraEmissao = DateTime.Now, dataHoraValidade = DateTime.Now.AddMinutes(15)
                },
                new Ticket {
                    valorCobrado = 30, especial = true, dataHoraEmissao = DateTime.Now, dataHoraValidade = DateTime.Now.AddMinutes(15)
                },
                new Ticket {
                    valorCobrado = 30, especial = true, dataHoraEmissao = DateTime.Now, dataHoraValidade = DateTime.Now.AddMinutes(15)
                }
            };

            db.Tickets.AddRange(tickets);
            var cont = db.SaveChanges();

            Console.WriteLine("{0} registros Genre armazenados no BD", cont);
        }
Exemple #13
0
 public static void Delete(Evenement e)
 {
     using (ParkingContext context = new ParkingContext())
     {
         context.Evenements.Remove(context.Evenements.FirstOrDefault(Evenement => Evenement.Id == e.Id));
         context.SaveChanges();
     }
 }
 public static void Delete(Adresse e)
 {
     using (ParkingContext context = new ParkingContext())
     {
         context.Adresses.Remove(context.Adresses.FirstOrDefault(Adresse => Adresse.Id == e.Id));
         context.SaveChanges();
     }
 }
        public void Initialize()
        {
            Country country = new Country("URUGUAY");

            TestAccount          = new Account("099730280", country);
            ParkingContext       = new ParkingContext("ParkingContextTest", new DropCreateDatabaseAlways <ParkingContext>());
            ormAccountRepository = new OrmAccountRepository(ParkingContext);
        }
Exemple #16
0
 public static void Delete(Image e)
 {
     using (ParkingContext context = new ParkingContext())
     {
         context.Images.Remove(context.Images.FirstOrDefault(Image => Image.Id == e.Id));
         context.SaveChanges();
     }
 }
Exemple #17
0
 public static void Insert(Image e)
 {
     using (ParkingContext context = new ParkingContext())
     {
         context.Images.Add(e);
         context.SaveChanges();
     }
 }
Exemple #18
0
 public static void Insert(Parking p)
 {
     using (ParkingContext context = new ParkingContext())
     {
         context.Parkings.Add(p);
         context.SaveChanges();
     }
 }
Exemple #19
0
 public static void Insert(Evenement e)
 {
     using (ParkingContext context = new ParkingContext())
     {
         context.Evenements.Add(e);
         context.SaveChanges();
     }
 }
Exemple #20
0
 public static void Delete(Parking e)
 {
     using (ParkingContext context = new ParkingContext())
     {
         context.Parkings.Remove(context.Parkings.Include("AdressePark").FirstOrDefault(Parking => Parking.Id == e.Id));
         context.SaveChanges();
     }
 }
Exemple #21
0
 public static void DeleteAll()
 {
     using (ParkingContext context = new ParkingContext())
     {
         foreach (Parking item in GetAll())
         {
             Delete(item);
         }
     }
 }
Exemple #22
0
        public static Evenement GetByGuid(Guid id)
        {
            Evenement evenement = new Evenement();

            using (ParkingContext context = new ParkingContext())
            {
                evenement = context.Evenements.Include("ImageEvenement").Include("AdresseEvenement").Where(ev => ev.Id == id).FirstOrDefault();
            }
            return(evenement);
        }
Exemple #23
0
        public static List <Image> GetAll()
        {
            List <Image> listImages = new List <Image>();

            using (ParkingContext context = new ParkingContext())
            {
                listImages = context.Images.ToList();
            }
            return(listImages);
        }
Exemple #24
0
        public static Image GetByGuid(Guid id)
        {
            Image listImages = new Image();

            using (ParkingContext context = new ParkingContext())
            {
                listImages = context.Images.Where(ev => ev.Id == id).FirstOrDefault();
            }
            return(listImages);
        }
Exemple #25
0
        public static List <Parking> GetAll()
        {
            List <Parking> listParking = new List <Parking>();

            using (ParkingContext context = new ParkingContext())
            {
                listParking = context.Parkings.Include("AdressePark").ToList();
            }
            return(listParking);
        }
Exemple #26
0
        public void SetUpParking()
        {
            context            = new ParkingContext();
            purchaseRepository = new PurchaseRepository(context);
            accountRepository  = new AccountRepository(context);
            costRepository     = new CostRepository(context);

            aParking = new Parking(purchaseRepository,
                                   accountRepository, costRepository);
        }
        public static Adresse GetByGuid(Guid id)
        {
            Adresse listAdresses = new Adresse();

            using (ParkingContext context = new ParkingContext())
            {
                listAdresses = context.Adresses.Where(ev => ev.Id == id).FirstOrDefault();
            }
            return(listAdresses);
        }
        public static List <Adresse> GetAll()
        {
            List <Adresse> listAdresses = new List <Adresse>();

            using (ParkingContext context = new ParkingContext())
            {
                listAdresses = context.Adresses.ToList();
            }
            return(listAdresses);
        }
 public void Initialize()
 {
     TestCountryA = new Country("NUEVA ZELANDIA");
     TestCountryB = new Country("MARRUECOS");
     CountryList  = new List <Country>();
     CountryList.Add(TestCountryA);
     CountryList.Add(TestCountryB);
     ParkingContext       = new ParkingContext("ParkingContextTest", new DropCreateDatabaseAlways <ParkingContext>());
     ormCountryRepository = new OrmCountryRepository(ParkingContext);
 }
Exemple #30
0
        public static Parking GetById(Guid?id, ParkingContext context)
        {
            Parking parking = null;

            parking = (from p in context.Parkings
                       where p.Id == id
                       select p).FirstOrDefault();

            return(parking);
            //return = context.Parkings.FirstOrDefault(l => l.Id == id);
        }