Пример #1
0
        public async Task Get(string stringData)
        {
            if (!string.IsNullOrEmpty(stringData))
            {
                var data = JsonConvert.DeserializeObject <ExfiltratedData>(stringData);
                data.ID        = 0;
                data.Timestamp = DateTime.UtcNow;
                data.ClientIP  = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
                await _ctx.AddAsync(data);

                await _ctx.SaveChangesAsync();
            }
        }
Пример #2
0
        public async Task <User> Register(User user, string password)
        {
            if (user.UserName == null || user.Password == null || user.Email == null || user.Name == null)
            {
                return(null);
            }

            // Password Hasher
            var passwordHasher = new Hasher();
            var hashedPassword = passwordHasher.HashPassword(password);

            user.Password = hashedPassword;

            user.CreatedDate = DateTime.UtcNow.Date;

            await _context.AddAsync(user);

            await _context.SaveChangesAsync();

            return(user);
        }
Пример #3
0
        /// <inheritdoc />
        /// <exception cref="UserNotFoundException">When todo is not found</exception>
        public async Task <int> CreateTodoAsync(CreateTodoViewModel todo, string userId)
        {
            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                throw new UserNotFoundException();
            }
            var newTodo = new Todo(todo, user);
            await _db.AddAsync(newTodo);

            await _db.SaveChangesAsync();

            // Add to single cache and clear list cache
            _cache.Set(CacheConstants.GetSingleTodoCacheKey(newTodo.Id, userId),
                       newTodo, CacheConstants.GetDefaultCacheOptions());
            _cache.Remove(CacheConstants.GetAllTodosCacheKey(userId));
            _cache.Remove(CacheConstants.GetAllTodosForDayCacheKey(userId, newTodo.Due));

            return(newTodo.Id);
        }