Ejemplo n.º 1
0
        public IActionResult PostRoom([FromQuery] string name, [FromBody] ClientConfigVM model)    //Register a new room to the Doorman Master
        {
            if (model == null || !model.ClientId.Equals(_clientId, StringComparison.OrdinalIgnoreCase) ||
                !model.ClientSecret.Equals(_clientSecret, StringComparison.OrdinalIgnoreCase))
            {
                return(BadRequest());
            }

            var result = _doormanService.RegisterRoom(name, model);

            if (result == null)
            {
                return(NotFound());
            }

            return(CreatedAtAction("GetRoom", new { roomId = result.RoomId }, result));
        }
Ejemplo n.º 2
0
        PostRoomResultVM IDoormanService.RegisterRoom(string name, ClientConfigVM model)
        {
            var result = new PostRoomResultVM();

            try
            {
                var dbModel =
                    _context.Rooms.SingleOrDefault(x => x.Description.Equals(name, StringComparison.OrdinalIgnoreCase));

                if (dbModel != null)
                {
                    result = Mapper.Map <Room, PostRoomResultVM>(dbModel);

                    var snapShotModels =
                        _context.RoomOccupancySnapshots.Where(x => x.RoomId == dbModel.RoomId);

                    if (snapShotModels.Any())
                    {
                        var snapShot = snapShotModels.OrderByDescending(x => x.CreateDateTime).First();
                        Mapper.Map <RoomOccupancySnapshot, PostRoomResultVM>(snapShot, result);
                    }
                }
                else
                {
                    dbModel = new Room
                    {
                        Description = name,
                        AccessToken = GetAccessToken()
                    };

                    _context.Rooms.Add(dbModel);

                    _context.SaveChanges();

                    result = Mapper.Map <Room, PostRoomResultVM>(dbModel);
                }

                return(result);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        public static string CreateToken(int userId, ClientConfigVM model)
        {
            var identity = GetClaimIdentity(userId, model.ClientId, model.ClientSecret);

            return(GetSecurityToken(identity));
        }