Ejemplo n.º 1
0
        public static double GetCurrentOccupiedSpace()
        {
            using var context = new StarWarsDbContext();

            return(context.Person.Any(p => p.ExitTime == null)
                ? context.Person.Where(p => p.ExitTime == null).Sum(p => p.Length)
                : 0.0);
        }
Ejemplo n.º 2
0
 public static bool IsDocked(StarWarsPerson person)
 {
     if (person == null)
     {
         throw new ArgumentNullException(nameof(person));
     }
     using var context = new StarWarsDbContext();
     return(context.Person.Any(p => p.Name == person.Name && p.ExitTime == null));
 }
Ejemplo n.º 3
0
        public static void AddNewCustomerDocking(StarWarsPerson person)
        {
            if (person == null)
            {
                throw new ArgumentNullException(nameof(person));
            }

            using var context = new StarWarsDbContext();
            person.EntryTime  = DateTime.Now;
            context.Person.Add(person);
            context.SaveChanges();
        }
Ejemplo n.º 4
0
        public static StarWarsPerson CheckOutCustomer(StarWarsPerson person)
        {
            if (person == null)
            {
                throw new ArgumentNullException(nameof(person));
            }
            using var context = new StarWarsDbContext();
            var item = context.Person.FirstOrDefault(p => p.Name == person.Name && p.ExitTime == null);

            if (item != null)
            {
                item.ExitTime = DateTime.Now;
                context.SaveChanges();
            }

            return(item);
        }