Example #1
0
        public IActionResult SetGuestSession([FromBody] GuestBasic data)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("An IP Address is required."));
                }
                if (data != null)
                {
                    if (_options != null)
                    {
                        _logger.LogInformation($"OPTION IS PRESENT is still present");
                    }

                    if (_ctx.Exist(data.IPAddress))
                    {
                        var theGuest = _mapper.Map <GuestSimple>(_ctx.GetGuestByIpOrId(data.IPAddress));
                        HttpContext.Session.SetString("GuestSession", JsonConvert.SerializeObject(theGuest));
                        if (!(theGuest.FirstVisit.ToShortDateString() == DateTime.Now.ToShortDateString()))
                        {
                            theGuest.LastVisit = DateTime.Now;
                            if (!_ctx.UpdateGuest(_mapper.Map <GuestEntity>(theGuest)))
                            {
                                _logger.LogInformation("Unable to update Last Visit.");
                                return(BadRequest("Unable to update Last Visit."));
                            }
                        }
                        _logger.LogInformation($"A guest session with IP: {theGuest.IPAddress} has been started.");
                        if (_options != null)
                        {
                            _logger.LogInformation($"{_options.FirstSeen} is still present");
                        }
                        return(Ok($"A session for guest ip: {theGuest.IPAddress} has successfully started."));
                    }
                    _logger.LogInformation("No guest with IP {data.IPAddress} was found.");
                    return(BadRequest($"No guest with IP {data.IPAddress} was found."));
                }
                _logger.LogInformation("No Valid guest data found.");
                return(BadRequest("No Valid guest data found"));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Unable to create a session.", ex);
                return(StatusCode(500, "The was and error found at SetGuestSesstion"));
            }
        }
Example #2
0
        public IActionResult CreateNewGuest(CreateGuestForRemap createGuest)
        {
            if (_user == null && _options != null)
            {
                if (_options.EnableGuest)
                {
                    if (!ModelState.IsValid)
                    {
                        return(BadRequest("Invalid Entry"));
                    }
                    if (_ctx.Exist(createGuest.IPAddress))
                    {
                        var result = _ctx.GetGuestByIpOrId(createGuest.IPAddress);
                        _logger.LogInformation("ReAdding GUEST");
                        return(Ok(result));
                    }
                    createGuest.FirstVisit = DateTime.Now;
                    createGuest.LastVisit  = DateTime.Now;
                    if (_ctx.AddNewGuest(_mapper.Map <GuestEntity>(createGuest)))
                    {
                        var guest = new GuestBasic()
                        {
                            IPAddress = createGuest.IPAddress
                        };

                        SetGuestSession(data: guest);
                        var final = _ctx.GetGuestByIpOrId(guest.IPAddress);

                        _logger.LogInformation("ADDING GUEST");
                        return(Ok(final));
                    }
                }
                _logger.LogInformation("Not set as a MEMBER is OPTIONS");
                return(BadRequest("Not set as a MEMBER is OPTIONS"));
            }
            return(BadRequest($" is currently logged in."));
        }