Esempio n. 1
0
        public async Task <Customer> Register(Customer customer, string password)
        {
            _hashing.CreatePasswordHash(password, out byte[] passworHash, out byte[] passwordSalt);

            customer.PasswordHash = passworHash;
            customer.PasswordSalt = passwordSalt;

            await _appContext.Customers.AddAsync(customer);

            await _appContext.SaveChangesAsync();

            return(customer);
        }
Esempio n. 2
0
        public async Task <IActionResult> UpdateCustomer(UpdateCustomerDto updateCustomerDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (await _unitOfWork.Customer.EmailExists(updateCustomerDto.Email, updateCustomerDto.ID))
            {
                return(BadRequest("Email already exists"));
            }

            if (await _unitOfWork.Customer.MobileExists(updateCustomerDto.Mobile, updateCustomerDto.ID))
            {
                return(BadRequest("Mobile already exists"));
            }

            var customerInDb = await _unitOfWork.Customer.
                               GetAsync(updateCustomerDto.ID);

            var customer = _mapper.Map <Customer>(updateCustomerDto);

            customer.DateOfBirth      = customerInDb.DateOfBirth;
            customer.Resident         = customerInDb.Resident;
            customer.PrivateID        = customerInDb.PrivateID;
            customer.RegistrationDate = customerInDb.RegistrationDate;
            customer.RegistrationIP   = customerInDb.RegistrationIP;

            _hashing.CreatePasswordHash(updateCustomerDto.Password, out byte[] passworHash, out byte[] passwordSalt);
            customer.PasswordHash = passworHash;
            customer.PasswordSalt = passwordSalt;

            bool result = await _unitOfWork.Customer.
                          UpdateAsync(customer, updateCustomerDto.ID);

            if (!result)
            {
                return(NoContent());
            }

            return(Ok(customer));
        }