public async Task RegisterAsync(CustomerViewModel accountViewModel)
        {
            var customer = _mapper.Map <Customer>(accountViewModel);

            customer.CustomerId = Guid.NewGuid().ToString();
            await _customerRepository.AddAsync(customer);
        }
Beispiel #2
0
        public async Task <CustomerSignUpResult> SignUpCustomerAsync(Customer customer)
        {
            CustomerSignUpResult    customerSignUpResult    = null;
            CustomerExistanceResult customerExistanceResult = await CustomerRepository.CustomerExistsAysnc(customer);

            if (customerExistanceResult == null)
            {
                customerSignUpResult = await CustomerRepository.AddAsync(customer);
            }
            else
            {
                if (customerExistanceResult.EmailAddress.Equals(customer.EmailAddress) &&
                    customerExistanceResult.PhoneNumber.Equals(customer.PhoneNumber))
                {
                    throw new CustomerAlreadyExistsException(customer.PhoneNumber, customer.EmailAddress);
                }
                if (customerExistanceResult.EmailAddress.Equals(customer.EmailAddress))
                {
                    throw new CustomerAlreadyExistsException(customer.EmailAddress);
                }
                if (customerExistanceResult.PhoneNumber.Equals(customer.PhoneNumber))
                {
                    throw new CustomerAlreadyExistsException(customer.PhoneNumber);
                }
            }
            if (customerSignUpResult == null || customerSignUpResult.CustomerSignUpStatus == CustomerSignUpStatus.Failed)
            {
                throw new CustomerSignUpFailedException(customer.EmailAddress);
            }

            return(customerSignUpResult);
        }
Beispiel #3
0
        public async Task <Guid> Handle(RegisterRedBetCustomerCommand request, CancellationToken cancellationToken)
        {
            var customer = new RedBetCustomer(request.FirstName, request.LastName, request.AddressStreet, request.AddressNumber, request.AddressZipCode, request.FavoriteFootballTeam);
            await _customerRepository.AddAsync(customer);

            return(customer.Id);
        }
Beispiel #4
0
        public async Task CreateAsync(string name, string surname, string phoneNumber, string flatNumber, string buildingNumber, string street, string city, string zipCode)
        {
            var customer = new Customer(name, surname, phoneNumber);

            customer.AddAddress(new CustomerAddress(flatNumber, buildingNumber, street, city, zipCode));
            await _customerRepository.AddAsync(customer);
        }
Beispiel #5
0
        public async Task <Customer> Add(string email, string name, int groupId)
        {
            try
            {
                var oldUser = await _customerRepository.FirstOrDefaultAsync(x => x.Email == email);

                if (oldUser != null)
                {
                    throw new ApplicationException("User already exist");
                }

                var cus = new Customer
                {
                    Email       = email,
                    Name        = name,
                    UserGroupId = groupId
                };

                await _customerRepository.AddAsync(cus);

                return(cus);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public async Task <ActionResult <CustomerForGetDTO> > Post(CustomerForAddDTO model)
        {
            if (await _customerRepository.IsExistByPhone(model.Phone).ConfigureAwait(true))
            {
                return(Conflict(new ApiResponse(409, StringConcatenates.Exist("Phone", model.Phone))));
            }

            if (await _customerRepository.IsExistByEmail(model.Email).ConfigureAwait(true))
            {
                return(Conflict(new ApiResponse(409, StringConcatenates.Exist("Email", model.Email))));
            }

            Customer customer = _mapper.Map <Customer>(model);
            string   password = SecurePassword.GeneratePassword(8);

            SecurePassword.CreatePasswordHash(password, out byte[] passwordHash, out byte[] passwordSalt);
            customer.PasswordHash = passwordHash;
            customer.PasswordSalt = passwordSalt;

            await _customerRepository.AddAsync(customer).ConfigureAwait(true);

            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            Email.Send("Momen", customer.Email, "password", password);

            CustomerForGetDTO customerDto = _mapper.Map <CustomerForGetDTO>(customer);

            return(Ok(customerDto));
        }
        public async Task <Guid> Handle(RegisterMrGreenCustomerCommand request, CancellationToken cancellationToken)
        {
            var customer = new MrGreenCustomer(request.FirstName, request.LastName, request.AddressStreet, request.AddressNumber, request.AddressZipCode, request.PersonalNumber);
            await _customerRepository.AddAsync(customer);

            return(customer.Id);
        }
            public async Task <IResult> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
            {
                var isCustomerExits = await _customerMongoRepository.GetListAsync(u => u.Username == request.Username);

                if (isCustomerExits.FirstOrDefault() != null)
                {
                    return(new ErrorResult(Messages.NameAlreadyExist));
                }

                var customer = new Customer
                {
                    //classın özellikleri buraya yazılır.
                    Username         = request.Username,
                    Accounts         = request.Accounts,
                    Active           = request.Active,
                    Address          = request.Address,
                    Birthdate        = request.Birthdate,
                    Email            = request.Email,
                    Name             = request.Name,
                    RecordDate       = DateTime.Now,
                    Tier_and_details = request.Tier_and_details
                };

                await _customerMongoRepository.AddAsync(customer);

                return(new SuccessResult(Messages.Added));
            }
        public async Task <IActionResult> Post([FromBody] AddCustomerViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            var customerType = await _customerTypeRepo.GetAsync(model.CustomerTypeId);

            if (customerType == null)
            {
                return(NotFound(Resources.Customers.CustomerResource.CustomerTypeNotFound));
            }

            if (await _customerRepo.IsExistNameAsync(model.Name))
            {
                ModelState.AddModelError("Name", Resources.Global.Common.ThisNameExist);
                return(BadRequest(ModelState.GetWithErrorsKey()));
            }

            var customer = new Customer(model.Name, customerType.Id, model.Note);

            var affectedRows = await _customerRepo.AddAsync(customer);

            if (affectedRows > 0)
            {
                _customerRepo.LoadReferences(customer);

                var viewModel = AutoMapper.Mapper.Map <CustomerViewModel>(customer);

                return(CreatedAtRoute("GetCustomer", new { id = customer.Number }, viewModel));
            }
            return(BadRequest());
        }
        public async Task <IActionResult> AddCustomerAsync([FromBody] CustomerCreateDto customerCreateDto)
        {
            if (customerCreateDto == null)
            {
                return(BadRequest("Please supplier customer details"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Customer toAdd = Mapper.Map <Customer>(customerCreateDto);

            _customerRepository.AddAsync(toAdd);

            bool result = await _customerRepository.SaveAsync();

            if (!result)
            {
                return(new StatusCodeResult(500));
            }

            return(CreatedAtRoute("GetSingleCustomer",
                                  new { id = toAdd.Id },
                                  Mapper.Map <CustomerDto>(toAdd)));
        }
Beispiel #11
0
        public Task <Maybe <CustomerDto> > CreateCustomerAsync(string name)
        {
            var customer    = Customer.Create(name);
            var customerDto = customer.Map(c => _converter.ToDto(c));

            return(customerDto.Map(async c => await _repository.AddAsync(c)));
        }
Beispiel #12
0
        public async Task <IActionResult> Create(CustomerModel customer)
        {
            var model       = Mapper.Map <Customer>(customer);
            var changesMade = await _repository.AddAsync(model);

            return(Ok(changesMade));
        }
        public async Task <ServiceResult <int> > Create(int companyId, CustomerCreateOrUpdateRequestViewModel viewModel)
        {
            var model = new Customer();

            MapViewModelToModel(viewModel, model);
            model.CompanyId = companyId;

            var validator        = new CustomerCreateOrUpdateRequestViewModelValidator();
            var validationResult = await validator.ValidateAsync(model);

            if (!validationResult.IsValid)
            {
                return(ServiceResultFactory.Fail <int>(validationResult));
            }

            await _repository.AddAsync(model);

            var changes = await _repository.SaveChangesAsync();

            if (changes == 0)
            {
                return(ServiceResultFactory.Fail <int>("Insert fails"));
            }
            return(ServiceResultFactory.Success(model.Id));
        }
        public async Task CreateOrModifyAsync(CustomerViewModel customer)
        {
            var entity = await _customerRepository.GetItemByOpenIdAsync(customer.OpenId);

            if (entity == null || entity.Id <= 0)
            {
                await _customerRepository.AddAsync(new Customer()
                {
                    AvatarUrl     = customer.AvatarUrl,
                    LastLoginTime = DateTime.Now,
                    NickName      = customer.NickName,
                    City          = customer.City,
                    Country       = customer.Country,
                    Gender        = customer.Gender,
                    OpenId        = customer.OpenId,
                    Province      = customer.Province,
                });
            }
            else
            {
                entity.AvatarUrl     = customer.AvatarUrl;
                entity.LastLoginTime = DateTime.Now;
                entity.NickName      = customer.NickName;
                entity.City          = customer.City;
                entity.Country       = customer.Country;
                entity.Gender        = customer.Gender;
                entity.Province      = customer.Province;

                await _customerRepository.UpdateAsync(entity);
            }
        }
        public async Task <CustomerDto> AddAsync(CustomerDto customerDto)
        {
            var customer = _mapper.Map <Customer>(customerDto);
            var result   = await _customerRepository.AddAsync(customer);

            return(_mapper.Map <CustomerDto>(result));
        }
Beispiel #16
0
        public async Task InitializeAsync()
        {
            if (!_applicationOptions.Value.SeedData)
            {
                _logger.LogInformation("Data initialization skipped.");

                return;
            }

            _logger.LogInformation("Initializing data...");

            var customers = GetCustomers().ToList();
            var products  = GetProducts().ToList();

            foreach (var customer in customers)
            {
                await _customerRepository.AddAsync(customer);
            }

            foreach (var product in products)
            {
                await _productRepository.AddAsync(product);
            }

            var orders = GetOrders(customers, products).ToList();

            foreach (var order in orders)
            {
                await _orderRepository.AddAsync(order);
            }

            _logger.LogInformation("Data initialized.");
        }
Beispiel #17
0
        public async Task <CustomerResponseModel> CreateCustomer(CustomerRequestModel customerRequestModel)
        {
            var customer        = _mapper.Map <Customer>(customerRequestModel);
            var createdCustomer = await _customerRepository.AddAsync(customer);

            return(_mapper.Map <CustomerResponseModel>(createdCustomer));
        }
        public async Task <string> Handle(CustomerCreateCommand request, CancellationToken cancellationToken)
        {
            var data = new Customer(request.Name, request.Description, request.Company, request.Phone, request.Mail, request.Address, identityService.GetOrganizationId(), identityService.GetUserId());
            await customerRepository.AddAsync(data);

            return(data.Id);
        }
Beispiel #19
0
        public async Task <IActionResult> PostAsync([FromBody] Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }


            try
            {
                await _customerRepo.AddAsync(customer);

                await _customerRepo.SaveChangeAsync();

                var returnedResource = Mapper.Map <Customer, CustomerReturnResource>(customer);

                return(Ok(returnedResource));
            }
            catch (Exception ex)
            {
                return(BadRequest(new List <string> {
                    ex.Message
                }));
            }
        }
        public async Task <IActionResult> Create([Bind("Firstname", "Lastname")] CustomerViewModel customerView)
        {
            mLogger.LogInformation("Customer/Create request");

            var firstname = customerView.Firstname;
            var lastname  = customerView.Lastname;

            if (!ModelState.IsValid)
            {
                return(Json(new JsonResponse(false, "Validation error")));
            }

            var customer = new CustomerModel {
                Name = firstname + " " + lastname
            };

            bool isNewCustomer = await mCustomerRepository.AddAsync(customer);

            if (!isNewCustomer)
            {
                return(Json(new JsonResponse(false, $"Customer {firstname} {lastname} already exists!")));
            }

            HttpContext.Session.Set <CustomerModel> (SESSION_KEY, customer);

            return(Json(new JsonResponse(true, "New user created!")));
        }
        public async Task TestRemoveAsync()
        {
            string id       = Id.ObjectId();
            var    customer = new Customer(id)
            {
                Name = "util"
            };
            await _customerRepository.AddAsync(customer);

            await _unitOfWork.CommitAsync();

            _unitOfWork.ClearCache();

            var result = await _customerRepository.SingleAsync(t => t.Id == id);

            Assert.NotNull(result);

            await _customerRepository.RemoveAsync(id);

            await _unitOfWork.CommitAsync();

            _unitOfWork.ClearCache();

            result = await _customerRepository.SingleAsync(t => t.Id == id);

            Assert.Null(result);
        }
Beispiel #22
0
 public async Task CreateAsync(Customer customer)
 {
     if (!IsValid(customer))
     {
         return;
     }
     await _customerRepository.AddAsync(customer);
 }
Beispiel #23
0
        public async Task HandleAsync(CustomerCreated @event)
        {
            if (await _customerRepository.ExistsAsync(@event.CustomerId))
            {
                throw new CustomerAlreadyExistsException(@event.CustomerId);
            }

            await _customerRepository.AddAsync(new Customer(@event.CustomerId));
        }
Beispiel #24
0
        public async Task <Customer> AddAsync(Customer customer)
        {
            if (!customer.IsValidForNewRegister())
            {
                return(customer);
            }

            return(await _customerRepository.AddAsync(customer));
        }
        public async Task <int> AddAsync(CustomerAddModel model)
        {
            var customer = CustomerFactory.Create(model, _userId);
            await _customerRepository.AddAsync(customer);

            await _unitOfWork.SaveChangesAsync();

            return(customer.Id);
        }
        public override async Task <Result> Handler(CreateCustomer message)
        {
            var customer = new Customer(message.FirstName, message.LastName, message.Email, message.IsActive);
            await _customerRepository.AddAsync(customer);

            await _customerRepository.SaveEntitiesAsync();

            return(new Result());
        }
        public async Task Handle(CustomerRegistrationConfirmedDomainEvent @event, CancellationToken cancellationToken)
        {
            var registration = await _customerRegistrationRepository.GetByIdAsync(
                new CustomerRegistrationId(@event.CustomerRegistrationId.Value)
                );

            var customer = registration.CreateCustomer(_customerChecker);

            await _customerRepository.AddAsync(customer);
        }
Beispiel #28
0
        public async Task <IActionResult> Create([Bind("CustomerId,Name,LegalId,Phone")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                await _customerRepository.AddAsync(customer);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Beispiel #29
0
        public async Task <CustomerVm> Handle(AddCustomerCommand request, CancellationToken cancellationToken)
        {
            var customer = _mapper.Map <Customer>(request);

            var newCustomer = await _repository.AddAsync(customer);

            _logger.LogInformation($"Customer {newCustomer.FirstName} {newCustomer.LastName} is successfully created.");

            return(_mapper.Map <CustomerVm>(newCustomer));
        }
        public async Task <Customer> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
        {
            var customer = await _customerRepository.AddAsync(request.Customer);

            var customerMessage = new CustomerMessage(_serviceId, customer);

            _messageProducer.SendMessage(_queueName, customerMessage);
            _logger.Log(LogLevel.Information, $"{DateTime.Now} - Enviada mensagem pelo ServiceId: {customerMessage.ServiceId} com RequestId: {customerMessage.RequestId}");
            return(await Task.FromResult(customer));
        }