Esempio n. 1
0
        public virtual IActionResult Update(long id, [FromBody] TEntity entity)
        {
            if (entity == null || !((IEntity <TId>)entity).Id.Equals(id))
            {
                return(BadRequest());
            }
            TEntity dbEntityMapped = this.MapOnUpdate(entity);

            _context.Update(dbEntityMapped);
            _context.SaveChanges();


            return(new ObjectResult(dbEntityMapped));
        }
Esempio n. 2
0
        public User Create(User user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }

            if (_context.User.Any(x => x.UserName == user.UserName))
            {
                throw new AppException("Username " + user.UserName + " is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _context.User.Add(user);
            _context.SaveChanges();

            return(user);
        }