コード例 #1
0
        public EnableOptionsEntity GetOption(string ip = "", int id = 0, DateTime?seen = null)
        {
            var option = new EnableOptionsEntity();

            if (!string.IsNullOrWhiteSpace(ip))
            {
                option = _ctx.EnableOptionsEntity.FirstOrDefault(o => o.IpAddress == ip);
            }
            if (id > 0)
            {
                option = _ctx.EnableOptionsEntity.FirstOrDefault(o => o.Id == id);
            }
            if (seen != null)
            {
                option = _ctx.EnableOptionsEntity.FirstOrDefault(o => o.FirstSeen == seen);
            }
            if (option == null || option.Id == 0)
            {
                return(null);
            }
            else
            {
                return(option);
            }
        }
コード例 #2
0
        public IActionResult EditOptions(EnableOptionsEntity editedOption)
        {
            int id = 0;

            var result = _ctx.GetOption(editedOption.IpAddress);

            if (result == null && _options != null)
            {
                id     = _options.Id;
                result = _ctx.GetOption(id: id);
            }
            result.EnableGuest    = editedOption.EnableGuest;
            result.IsMember       = editedOption.IsMember;
            result.IsUnregistered = editedOption.IsUnregistered;
            result.IsAnonymous    = editedOption.IsAnonymous;
            result.IsLiving       = editedOption.IsLiving;
            result.LastSeen       = DateTime.Now;
            result.VisitCount     = 0;

            if (_ctx.EditOption(result))
            {
                SetOptionsSession(result);
                if (_options != null)
                {
                    _options.EnableGuest    = editedOption.EnableGuest;
                    _options.IsMember       = editedOption.IsMember;
                    _options.IsUnregistered = editedOption.IsUnregistered;
                    _options.IsAnonymous    = editedOption.IsAnonymous;
                    _options.LastSeen       = DateTime.Now;
                }
                else
                {
                    _logger.LogInformation("No Options found");
                }
                if (!_options.IsAnonymous)
                {
                    var finalOption = _ctx.GetOption(_options.IpAddress);
                    _logger.LogInformation("Option has been edited");
                    return(Ok(finalOption));
                }
                _logger.LogInformation("Option ANONYMOUS has been edited");
                return(Ok(_options));
            }
            return(BadRequest("This Option could not be changed"));
        }
コード例 #3
0
        public IActionResult EnableOption(CreateEnableOptionsforRemap createOptions)
        {
            var optionResult = new EnableOptionsEntity();

            if (!string.IsNullOrEmpty(createOptions.IpAddress))
            {
                optionResult = _ctx.GetOption(createOptions.IpAddress);
            }
            else
            {
                optionResult = null;
            }
            if (optionResult == null && !string.IsNullOrEmpty(createOptions.IpAddress))
            {
                createOptions.FirstSeen = DateTime.Now;
                createOptions.LastSeen  = DateTime.Now;
                if (_ctx.AddOption(_mapper.Map <EnableOptionsEntity>(createOptions)))
                {
                    var result      = _ctx.GetOption(createOptions.IpAddress);
                    var finalResult = SetOptionsSession(result);
                    _logger.LogInformation("An option has been created and a session has been started");
                    return(Ok(finalResult));
                }
                return(BadRequest("Unable to create option"));
            }

            if (_options == null)
            {
                if (createOptions.IsAnonymous)
                {
                    createOptions.FirstSeen = DateTime.Now;
                    createOptions.LastSeen  = DateTime.Now;
                    if (_ctx.AddOption(_mapper.Map <EnableOptionsEntity>(createOptions)))
                    {
                        var result      = _ctx.GetOption(seen: createOptions.FirstSeen);
                        var finalResult = SetOptionsSession(result);
                        _logger.LogInformation("An ANON option has been created and a session has been started");
                        return(Ok(finalResult));
                    }
                    return(BadRequest("Unable to create option"));
                }
            }
            _logger.LogInformation($"This option for ip: {createOptions.IpAddress} already exists");
            return(Ok(optionResult));
        }
コード例 #4
0
 public EnableOptionsEntity SetOptionsSession(EnableOptionsEntity createOptionSession)
 {
     HttpContext.Session.SetString("OptionsSession", JsonConvert.SerializeObject(createOptionSession));
     return(_options);
 }
コード例 #5
0
 public bool EditOption(EnableOptionsEntity editOption)
 {
     _ctx.EnableOptionsEntity.Attach(editOption);
     _ctx.Entry(editOption).State = EntityState.Modified;
     return(Save());
 }
コード例 #6
0
 public bool AddOption(EnableOptionsEntity addOption)
 {
     _ctx.EnableOptionsEntity.Add(addOption);
     return(Save());
 }