Ejemplo n.º 1
0
        public TodoItem Post([FromBody] TodoItem item)
        {
            var user = (User)HttpContext.Items["User"];

            var maxSortRank = _context.TodoItems.Where(x => x.IsActive == true && x.UserId == user.Id).Max(x => x.SortRank);

            item.SortRank = maxSortRank == null ? 1000 : maxSortRank + 1000;

            item.IsActive = true;
            item.UserId   = user.Id;

            _context.Add(item);
            _context.SaveChanges();
            return(item);
        }
Ejemplo n.º 2
0
        public bool Register(string username, string password)
        {
            bool isUsernameTaken = _dbContext.Users.Where(x => x.Username == username).Count() > 0;

            if (!isUsernameTaken)
            {
                byte[] passwordHash, passwordSalt;
                CreatePasswordHash(password, out passwordHash, out passwordSalt);

                _dbContext.Users.Add(new User {
                    Username     = username,
                    PasswordHash = passwordHash,
                    PasswordSalt = passwordSalt
                });

                _dbContext.SaveChanges();
                return(true);
            }

            return(false);
        }