예제 #1
0
        public void Logout(string username, string deviceId)
        {
            var existedCustomer = _customerRepository.Get(x => x.Username == username);
            var customerDevice  = _customerDeviceRepository.Get(x => x.DeviceId == deviceId && x.CustomerId == existedCustomer.Id);

            if (customerDevice != null)
            {
                customerDevice.IsLogout = true;
                _customerDeviceRepository.Update(customerDevice);
                _unitOfWork.CommitChanges();
            }
        }
예제 #2
0
        public Customer CheckCustomerLogin(LoginViewModel loginViewModel)
        {
            var customer = _customerRepository.Get(x => (x.Username.Equals(loginViewModel.Username) ||
                                                         x.PhoneNumber.Equals(loginViewModel.Username)) &&
                                                   x.PasswordHash.Equals(_customerService.HashPassword(loginViewModel.Password, Convert.FromBase64String(x.SaltPasswordHash))) &&
                                                   x.IsActive == true && x.Deleted == false);

            if (customer == null)
            {
                return(null);
            }
            var customerDevice = _customerDeviceRepository.Get(x => x.DeviceId == loginViewModel.DeviceId);

            if (customerDevice == null)
            {
                if (!string.IsNullOrEmpty(loginViewModel.DeviceId))
                {
                    customerDevice = new CustomerDevice
                    {
                        CustomerId = customer.Id,
                        DeviceId   = loginViewModel.DeviceId,
                        IsLogout   = false
                    };
                    _customerDeviceRepository.Add(customerDevice);
                }
            }
            else
            {
                customerDevice.IsLogout   = false;
                customerDevice.CustomerId = customer.Id;
                _customerDeviceRepository.Update(customerDevice);
            }
            _unitOfWork.CommitChanges();

            return(customer);
        }