Beispiel #1
0
        public Model.Users Register(UserVM request, string password)
        {
            //byte[] passwordHash, passwordSalt;
            //var user = _mapper.Map<Database.Users>(req);

            //CreatePasswordHash(password, out passwordHash, out passwordSalt);

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

            // _context.Users.Add(user);
            // _context.SaveChanges();


            var entity = _mapper.Map <Users>(request);

            if (request.Password != request.PasswordConfirm)
            {
                throw new Exception("Password and password confirm not matched !");
            }
            entity.PasswordSalt = HashGenerator.GenerateSalt();
            entity.PasswordHash = HashGenerator.GenerateHash(entity.PasswordSalt, request.Password);

            _context.Add(entity);
            _context.SaveChanges();

            return(_mapper.Map <Model.Users>(entity));
        }
Beispiel #2
0
        public void Delete(int id)
        {
            var result = _context.Set <TDatabase>().Find(id);

            if (result == null)
            {
                throw new ArgumentNullException();
            }
            else
            {
                _context.Set <TDatabase>().Remove(result);
                _context.SaveChanges();
            }
        }