Exemplo n.º 1
0
        public async Task <bool> UpdateAsync(long id, CustomerForRegistration customerDto)
        {
            var customer = await _customerRepository.GetById(id);

            _mapper.Map(customer, customerDto);
            try
            {
                await _customerRepository.SaveAll();
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        public async Task <bool> CreateFromDtoAsync(CustomerForRegistration customerDto, User user)
        {
            var customer = _mapper.Map <Domain.Customer>(customerDto);

            if (customer.User == null)
            {
                customer.User   = user;
                customer.UserId = user.Id;
            }
            if (customer.DateOfBirth == null)
            {
                customer.DateOfBirth = new DateTime(customerDto.DateOfBirth);
            }
            customer.DateOfRegistration = DateTime.Now;
            if (customer.Barcode == null)
            {
                customer.Barcode = Guid.NewGuid().NewShortGuid();
            }
            if (customer.Gender == null)
            {
                customer.Gender = "Male";
            }
            if (customer.Transactions == null)
            {
                customer.Transactions = new List <Transaction>();
            }
            if (customer.FavoritePartners == null)
            {
                customer.FavoritePartners = new List <FavoritePartners>();
            }
            if (customer.CustomersBalances == null)
            {
                customer.CustomersBalances = new List <CustomersBalance>();
            }
            if (customer.Reviews == null)
            {
                customer.Reviews = new List <Review>();
            }
            try
            {
                await _customerRepository.Add(customer);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        public async Task <bool> CustomerRegistration(CustomerForRegistration customerDto)
        {
            var user = new User {
                Email = customerDto.Email, UserName = customerDto.UserName, PhoneNumber = customerDto.PhoneNumber
            };
            var userCreating = await _userManager.CreateAsync(user, customerDto.Password);

            if (userCreating.Succeeded)
            {
                await _userManager.AddToRoleAsync(user, "Customer");

                var customerCreating = await _customerService.CreateFromDtoAsync(customerDto, user);

                return(customerCreating);
            }
            else
            {
                return(userCreating.Succeeded);
            }
        }
Exemplo n.º 4
0
        public async Task <bool> CreateFromDtoAsync(CustomerForRegistration customerDto, User user)
        {
            var customer = _mapper.Map <Domain.Customer>(customerDto);

            if (customer.UserId == 0)
            {
                customer.UserId = user.Id;
            }
            customer.DateOfRegistration = DateTime.Now;
            customer.Barcode            = customer.Barcode ?? Guid.NewGuid().NewShortGuid();
            try
            {
                await _customerRepository.Add(customer);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> CustomerRegistration(CustomerForRegistration customer)
        {
            var result = await _accountService.CustomerRegistration(customer);

            return(Ok(result));
        }