Exemplo n.º 1
0
        private static DoorStatus MapLockBooleansToDoorStatus(RegisterDoorRequestModel model)
        {
            DoorStatus status = DoorStatus.Unknown;

            if (!model.LockMagBondStatus && !model.LockReedStatus)
            {
                status = DoorStatus.Open;
            }
            if (!model.LockMagBondStatus && !model.LockReedStatus && (model.LockTriggerStatus || model.LockRequestExitStatus))
            {
                status = DoorStatus.Locking;
            }
            if (!model.LockMagBondStatus && model.LockReedStatus)
            {
                status = DoorStatus.Closed;
            }
            if (model.LockMagBondStatus && model.LockReedStatus)
            {
                status = DoorStatus.Locked;
            }
            if (model.LockMagBondStatus && !model.LockReedStatus)
            {
                status = DoorStatus.Fault;
            }
            if (model.LockRequestExitStatus)
            {
                status = DoorStatus.UnlockRequested;
            }

            return(status);
        }
Exemplo n.º 2
0
        public ActionResult <RegisterDoorResponseModel> RegisterDoor(RegisterDoorRequestModel model)
        {
            if (model == null)
            {
                return new RegisterDoorResponseModel {
                           Success = false
                }
            }
            ;
            if (string.IsNullOrEmpty(model.MacAddress))
            {
                return new RegisterDoorResponseModel {
                           Success = false
                }
            }
            ;

            DoorStatus status = MapLockBooleansToDoorStatus(model);

            var door = DataContext.Doors.FirstOrDefault(d => d.MacAddress == model.MacAddress);

            if (door == null)
            {
                door = new Door()
                {
                    MacAddress       = model.MacAddress,
                    Name             = "Unknown",
                    Status           = status,
                    CreatedTimestamp = DateTime.Now
                };

                DataContext.Add(door);
            }
            door.LastHeartbeatTimestamp = DateTime.Now;
            door.IsDeleted = false;
            door.Status    = status;

            int remoteUnlockRequestSeconds = door.RemoteUnlockRequestSeconds ?? 0;

            if (remoteUnlockRequestSeconds != 0)
            {
                door.RemoteUnlockRequestSeconds = null;
            }

            DataContext.SaveChanges();

            return(new RegisterDoorResponseModel
            {
                Success = true,
                DoorId = door.Id,
                RemoteUnlockRequestSeconds = remoteUnlockRequestSeconds
            });
        }