コード例 #1
0
        private void UpdateAutoReservations(object state)
        {
            //Get json from rest api
            var IpToMacActiveUsers = new Dictionary <string, string>();
            var macToUser          = new Dictionary <string, string>();

            foreach (var ipMac in IpToMacActiveUsers)
            {
                var activeUser    = macToUser[ipMac.Value];
                var userIpAddress = ipMac.Key;
                var desk          = new Desk();
                using (var db = new FlexSeatingContext())
                {
                    desk = db.Desk.Where(x => x.IpAddress == userIpAddress).FirstOrDefault();
                }
                if (desk.Reservations.Count == 0)
                {
                    desk.Reservations.Add(new Reservations()
                    {
                        Date   = DateTime.Now,
                        UserId = activeUser,
                        DeskId = desk.Id,
                        Desk   = desk
                    });
                }
            }
        }
コード例 #2
0
 public Floor GetFloor(int floorId)
 {
     using (var dbContext = new FlexSeatingContext())
     {
         return(dbContext.Floor.Where(x => x.Id == floorId).FirstOrDefault());
     }
 }
コード例 #3
0
 public Building GetBuilding(int buildingId)
 {
     using (var dbContext = new FlexSeatingContext())
     {
         return(dbContext.Building.Include(x => x.Floor).Where(x => x.Id == buildingId).FirstOrDefault());
     }
 }
コード例 #4
0
        public List <Building> GetBuildings(DateTime now)
        {
            using (var dbContext = new FlexSeatingContext())
            {
                var date = new DateTime(now.Year, now.Month, now.Day);

                var todayReservations = dbContext.Reservations.Where(x => x.Date == date).ToList();
                var buildings         = dbContext.Building
                                        .Include(x => x.Floor)
                                        .ThenInclude(y => y.Desk)
                                        .ToList();



                foreach (var b in buildings)
                {
                    foreach (var f in b.Floor)
                    {
                        f.Desk = f.Desk.OrderBy(x => x.Name).ToList();
                        foreach (var d in f.Desk)
                        {
                            foreach (var r in todayReservations)
                            {
                                if (r.DeskId == d.Id)
                                {
                                    d.Reservations.Add(r);
                                }
                            }
                        }
                    }
                }

                return(buildings);
            }
        }
コード例 #5
0
        public void CancelReservation(int reservationId, string user)
        {
            using (var dbContext = new FlexSeatingContext())
            {
                var res = dbContext.Reservations.Where(x => x.Id == reservationId).FirstOrDefault();
                if (res != null && user == res.UserId)
                {
                    dbContext.Reservations.Remove(res);
                }

                dbContext.SaveChanges();
            }
        }
コード例 #6
0
 public void ReserveDesk(int deskId, string user, DateTime date)
 {
     using (var dbContext = new FlexSeatingContext())
     {
         var num = dbContext.Reservations.Where(x => (x.Date == date && x.UserId == user)).Count();
         if (num == 0)
         {
             var res = new Reservations()
             {
                 DeskId = deskId,
                 UserId = user,
                 Date   = date
             };
             dbContext.Reservations.Add(res);
             dbContext.SaveChanges();
         }
     }
 }