public async Task <IActionResult> UpdateUser(int id, [FromBody] UserForUpdateDto user)
        {
            var userEntity = HttpContext.Items["entity"] as User;

            if (!string.IsNullOrEmpty(user.password) && user.password != null)
            {
                AuthExtensions.CreatePasswordHash(user.password, out byte[] passwordHash, out byte[] passwordSalt);
                user.passwordHash = passwordHash;
                user.passwordSalt = passwordSalt;
            }
            else
            {
                user.passwordHash = userEntity.passwordHash;
                user.passwordSalt = userEntity.passwordSalt;
            }

            _mapper.Map(user, userEntity);

            _repository.User.UpdateUser(userEntity);
            await _repository.SaveAsync();

            var userResult = new UserDto();
            var token      = string.Empty;

            this.CreateUserResponse(userEntity, out userResult, out token);

            return(Ok(new {
                user = userResult,
                token
            }));
        }
        public async Task <IActionResult> CreateCustomer([FromBody] CustomerCreationDto customer)
        {
            var customerEntity = _mapper.Map <Customer>(customer);

            AuthExtensions.CreatePasswordHash(customer.password, out byte[] passwordHash, out byte[] passwordSalt);
            customer.passwordHash = passwordHash;
            customer.passwordSalt = passwordSalt;

            _repository.Customer.CreateCustomer(customerEntity);
            await _repository.SaveAsync();

            var createdCustomer = _mapper.Map <CustomerDto>(customerEntity);

            return(CreatedAtRoute("CustomerById", new { id = createdCustomer.customerId }, createdCustomer));
        }
        public async Task <IActionResult> CreateUser([FromBody] UserCreationDto user)
        {
            var userEntity = _mapper.Map <User>(user);

            AuthExtensions.CreatePasswordHash(user.password, out byte[] passwordHash, out byte[] passwordSalt);
            userEntity.passwordHash = passwordHash;
            userEntity.passwordSalt = passwordSalt;

            _repository.User.CreateUser(userEntity);
            await _repository.SaveAsync();

            var createdUser = _mapper.Map <UserDto>(userEntity);

            return(CreatedAtRoute("UserById", new { id = createdUser.userId }, createdUser));
        }
        public async Task <IActionResult> UpdateCustomer(int id, [FromBody] CustomerForUpdateDto customer)
        {
            var customerEntity = HttpContext.Items["entity"] as Customer;

            if (!string.IsNullOrEmpty(customer.password))
            {
                AuthExtensions.CreatePasswordHash(customer.password, out byte[] passwordHash, out byte[] passwordSalt);
                customer.passwordHash = passwordHash;
                customer.passwordSalt = passwordSalt;
            }
            else
            {
                customer.passwordHash = customerEntity.passwordHash;
                customer.passwordSalt = customerEntity.passwordSalt;
            }

            _mapper.Map(customer, customerEntity);

            _repository.Customer.UpdateCustomer(customerEntity);
            await _repository.SaveAsync();

            return(NoContent());
        }