public async Task UpdateCustomerAsync_WhenUpdatingCountryForUserWithNoAddress_OnlyCountryIsUpdated()
        {
            //Arrange
            var stripeCustomerRepositoryMock             = new StripeCustomerRepositoryMock();
            var stripeCheckoutSessionRepositoryMock      = new StripeCheckoutSessionRepositoryMock();
            var stripeBillingPortalSessionRepositoryMock = new StripeBillingPortalSessionRepositoryMock();
            var userManagementServiceMock = new UserManagementServiceMock();
            var priceNameToIdMapper       = new DevPriceNameToIdMapper();

            StripePaymentService stripePaymentService = new StripePaymentService(stripeCustomerRepositoryMock,
                                                                                 stripeCheckoutSessionRepositoryMock, stripeBillingPortalSessionRepositoryMock,
                                                                                 userManagementServiceMock, priceNameToIdMapper);

            string customerId = "cus_id1";
            string country    = "PL";

            var updatedCustomer = new UpdateCustomerDto(customerId, country);

            //Act
            var returnedCustomer = await stripePaymentService.UpdateCustomerAsync(updatedCustomer);


            //Assert
            Assert.Equal(country, returnedCustomer.Country);
            Assert.Null(returnedCustomer.City);
            Assert.Null(returnedCustomer.PostalCode);
            Assert.Null(returnedCustomer.Line1);
            Assert.Null(returnedCustomer.Line2);
            Assert.Null(returnedCustomer.State);
        }
Beispiel #2
0
        public IActionResult Update(long id, [FromBody] UpdateCustomerDto item)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var customerNameOrError = CustomerName.Create(item.Name);

                if (customerNameOrError.IsFailure)
                {
                    return(BadRequest(customerNameOrError.Error));
                }

                Customer customer = _customerRepository.GetById(id);
                if (customer == null)
                {
                    return(BadRequest("Invalid customer id: " + id));
                }

                customer.Name = customerNameOrError.Value;
                _customerRepository.SaveChanges();

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(500, new { error = e.Message }));
            }
        }
        public async Task <IActionResult> UpdateAsync([FromRoute] int id, [FromBody] UpdateCustomerDto updateItem, CancellationToken cancellationToken)
        {
            if (await this._customerService.UpdateAsync(id, updateItem, cancellationToken))
            {
                return(StatusCode(StatusCodes.Status200OK));
            }

            return(StatusCode(StatusCodes.Status400BadRequest, new ErrorDetailDto("Cannot update customer")));
        }
Beispiel #4
0
 public async Task <IActionResult> UpdateAsync(Guid id, [FromBody] UpdateCustomerDto request)
 {
     return(await this.ExecuteCommandAsync(new UpdateCustomerRequest()
     {
         Id = id, Name = request.Name
     }, (UpdateCustomerResponse response) =>
     {
         return this.Mapper.Map <Dto.CustomerDto>(response.Customer);
     }));
 }
Beispiel #5
0
        public async Task <CustomerDto> UpdateAsync(UpdateCustomerDto input)
        {
            var customer = await _repository.GetAsync(input.Value.Id);

            ObjectMapper.Map <CustomerDto, Customer>(input.Value, customer);

            var updatedCustomer = await _repository.UpdateAsync(customer);

            return(ObjectMapper.Map <CustomerDto>(updatedCustomer));
        }
Beispiel #6
0
        public void Update(UpdateCustomerDto dTO)
        {
            var Customer = _DB.Customers.SingleOrDefault(x => x.Id == dTO.Id && !x.IsDelete);

            Customer.Name    = dTO.Name;
            Customer.Address = dTO.Address;
            Customer.Phone   = dTO.Phone;
            _DB.Customers.Update(Customer);
            _DB.SaveChanges();
        }
Beispiel #7
0
        public async Task <bool> Put(int id, [FromBody] UpdateCustomerDto dto)
        {
            var item = await _customerService.GetByIdAsync(id);

            if (item == null)
            {
                throw new ArgumentException("没有找到指定id的记录");
            }
            var result = await _customerService.UpdateCustomerAsync(dto);

            return(result);
        }
        public async Task PaymentMethodAttachedAsync(PaymentMethod paymentMethod)
        {
            var updatedCustomer =
                new UpdateCustomerDto(paymentMethod.CustomerId, paymentMethod.BillingDetails?.Address?.Country)
            {
                City       = paymentMethod.BillingDetails?.Address?.City,
                Line1      = paymentMethod.BillingDetails?.Address?.Line1,
                Line2      = paymentMethod.BillingDetails?.Address?.Line2,
                State      = paymentMethod.BillingDetails?.Address?.State,
                PostalCode = paymentMethod.BillingDetails?.Address?.PostalCode
            };

            await _stripePaymentService.UpdateCustomerAsync(updatedCustomer);
        }
Beispiel #9
0
        /// <summary>
        /// Update information in stripe database
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <CustomerDto> UpdateCustomer(UpdateCustomerDto dto)
        {
            var options = new CustomerUpdateOptions
            {
                Description = dto.Description,
                SourceToken = dto.SourceToken,
                Email       = dto.Email
            };

            var service = new CustomerService();

            return(CustomerMapper.MapCustomerToCustomerDto(
                       await service.UpdateAsync(dto.CustomerId, options)));
        }
Beispiel #10
0
        public async Task <ServiceResponse <GetCustomerDto> > updateCustomer(UpdateCustomerDto customer)
        {
            ServiceResponse <GetCustomerDto> response = new ServiceResponse <GetCustomerDto>();
            Customer _customer = await _context.Customers
                                 .FirstOrDefaultAsync(c => c.UserId == GetUserId());

            _customer.Bonus       = customer.Bonus;
            _customer.Name        = customer.Name;
            _customer.PhoneNumber = customer.PhoneNumber;
            _customer.Surname     = customer.Surname;

            await _context.SaveChangesAsync();

            response.Data = _mapper.Map <GetCustomerDto>(_customer);
            return(response);
        }
        public IActionResult UpdateCustomer(UpdateCustomerDto updateCustomerDto)
        {
            var result = _customerService.UpdateCustomer(
                updateCustomerDto.Id,
                updateCustomerDto.Name,
                updateCustomerDto.Address,
                updateCustomerDto.City,
                updateCustomerDto.Phone
                );

            if (!result.IsFaulted)
            {
                return(Ok(result.Payload));
            }

            return(NotFound(result.ErrorMessage));
        }
        public IActionResult Update(long id, [FromBody] UpdateCustomerDto item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Customer customer = _customerRepository.GetById(id);

            if (customer == null)
            {
                return(Error("Invalid customer id: " + id));
            }

            customer.Name = CustomerName.Create(item.Name).Value;

            return(Ok());
        }
Beispiel #13
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));
        }
        public async Task UpdateCustomerAsync_WhenUpdatingWholeAddress_EveryAddressPropertyIsPopulated()
        {
            //Arrange
            var stripeCustomerRepositoryMock             = new StripeCustomerRepositoryMock();
            var stripeCheckoutSessionRepositoryMock      = new StripeCheckoutSessionRepositoryMock();
            var stripeBillingPortalSessionRepositoryMock = new StripeBillingPortalSessionRepositoryMock();
            var userManagementServiceMock = new UserManagementServiceMock();
            var priceNameToIdMapper       = new DevPriceNameToIdMapper();

            StripePaymentService stripePaymentService = new StripePaymentService(stripeCustomerRepositoryMock,
                                                                                 stripeCheckoutSessionRepositoryMock, stripeBillingPortalSessionRepositoryMock,
                                                                                 userManagementServiceMock, priceNameToIdMapper);

            string customerId = "cus_id1";
            string country    = "PL";
            string city       = "Lodz";
            string postalCode = "90-608";
            string line1      = "Piotrkowska 60/25";
            string line2      = "";
            string state      = "";

            var updatedCustomer = new UpdateCustomerDto(customerId, country)
            {
                City       = city,
                PostalCode = postalCode,
                Line1      = line1,
                Line2      = line2,
                State      = state,
            };

            //Act
            var returnedCustomer = await stripePaymentService.UpdateCustomerAsync(updatedCustomer);


            //Assert
            Assert.Equal(country, returnedCustomer.Country);
            Assert.Equal(city, returnedCustomer.City);
            Assert.Equal(postalCode, returnedCustomer.PostalCode);
            Assert.Equal(line1, returnedCustomer.Line1);
            Assert.Equal(line2, returnedCustomer.Line2);
            Assert.Equal(state, returnedCustomer.State);
        }
Beispiel #15
0
        public IActionResult Update(long id, [FromBody] UpdateCustomerDto item)
        {
            var customerNameOrError = CustomerName.Create(item.Name);

            if (customerNameOrError.IsFailure)
            {
                return(Error(customerNameOrError.Error));
            }

            Customer customer = _customerRepository.GetById(id);

            if (customer == null)
            {
                return(Error("Invalid customer id: " + id));
            }

            customer.Name = customerNameOrError.Value;

            return(Ok());
        }
Beispiel #16
0
        public IActionResult Update(long id, [FromBody] UpdateCustomerDto item)
        {
            Result <CustomerName> customerNameOrError = CustomerName.Create(item.FirstName);

            if (customerNameOrError.IsFailure)
            {
                return(BadRequest(customerNameOrError.Error));
            }

            Customer customer = _customerRepository.Read(id);

            if (customer == null)
            {
                return(BadRequest("Invalid customer id: " + id));
            }

            customer.FirstName = customerNameOrError.Value;

            return(Ok());
        }
        public async Task <IActionResult> PutAsync(string id, UpdateCustomerDto updateCustomerDto)
        {
            var customer = await _customerRepository.GetByIDAsync(id);

            if (customer == null)
            {
                return(NotFound());
            }

            customer.CustomerName = updateCustomerDto.CustomerName;
            customer.MobileNumber = updateCustomerDto.MobileNumber;
            customer.MailAddress  = updateCustomerDto.MailAddress;

            await _customerRepository.UpdateAsync(customer);

            await _publishEndpoint.Publish(new CustomerUpdated(
                                               customer.CustomerCID, customer.CustomerName, customer.MobileNumber, customer.MailAddress
                                               ));

            return(NoContent());
        }
Beispiel #18
0
        public async Task <int> Update(int id, UpdateCustomerDto dto, string userId)
        {
            var oldCustomer = await _dbContext.Customer.SingleOrDefaultAsync(x => x.Id == id);

            if (oldCustomer == null)
            {
                throw _notFoundException;
            }

            if (id != dto.Id)
            {
                throw new UpdateEntityException(ExceptionMessage.UpdateEntityIdError);
            }

            var updatedCustomer = _mapper.Map(dto, oldCustomer);

            updatedCustomer.UpdatedAt = DateTime.Now;
            updatedCustomer.UpdatedBy = userId;

            _dbContext.Customer.Update(updatedCustomer);
            await _dbContext.SaveChangesAsync();

            return(updatedCustomer.Id);
        }
Beispiel #19
0
        public async Task <ActionResult <Customer> > Customer([FromBody] UpdateCustomerDto customerDto)
        {
            try
            {
                var getCommand = new GetEntityByIdQuery <Customer> {
                    Id = customerDto.Id
                };
                var customer = await mediator.Send(getCommand);

                if (customer == null)
                {
                    return(BadRequest($"No customer found with id {customerDto.Id}"));
                }

                var updateCommand = new UpdateEntityCommand <Customer> {
                    Entity = mapper.Map <Customer>(customerDto)
                };
                return(await mediator.Send(updateCommand));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        [Fact] public async Task UpdateCustomerAsync_WhenUpdatingCountryForUserWithAddress_OnlyCountryPropertyIsUpdated()
        {
            //Arrange
            var stripeCustomerRepositoryMock             = new StripeCustomerRepositoryMock();
            var stripeCheckoutSessionRepositoryMock      = new StripeCheckoutSessionRepositoryMock();
            var stripeBillingPortalSessionRepositoryMock = new StripeBillingPortalSessionRepositoryMock();
            var userManagementServiceMock = new UserManagementServiceMock();
            var priceNameToIdMapper       = new DevPriceNameToIdMapper();

            StripePaymentService stripePaymentService = new StripePaymentService(stripeCustomerRepositoryMock,
                                                                                 stripeCheckoutSessionRepositoryMock, stripeBillingPortalSessionRepositoryMock,
                                                                                 userManagementServiceMock, priceNameToIdMapper);

            string customerId         = "cus_id3";
            string newCountry         = "UK";
            string expectedCity       = "Lodz";
            string expectedPostalCode = "90-608";
            string expectedLine1      = "Piotrkowska 60/25";
            string expectedLine2      = null;
            string expectedState      = "lodzkie";

            var updatedCustomer = new UpdateCustomerDto(customerId, newCountry);

            //Act
            var returnedCustomer = await stripePaymentService.UpdateCustomerAsync(updatedCustomer);


            //Assert
            Assert.Equal(newCountry, returnedCustomer.Country);

            Assert.Equal(expectedCity, returnedCustomer.City);
            Assert.Equal(expectedPostalCode, returnedCustomer.PostalCode);
            Assert.Equal(expectedLine1, returnedCustomer.Line1);
            Assert.Equal(expectedLine2, returnedCustomer.Line2);
            Assert.Equal(expectedState, returnedCustomer.State);
        }
Beispiel #21
0
 public IActionResult Put(int id, [FromBody] UpdateCustomerDto model) =>
 _mapper.Map <CustomerUpdateModel>(model)
 .Map(x => _commandRepo.Update(id, x))
 .Map(x => AllOk(new { updated = x }))
 .Reduce(_ => NotFound(), error => error is RecordNotFound)
 .Reduce(_ => InternalServerError(), x => _logger.LogError(x.ToString()));
Beispiel #22
0
 public async Task <ValidationResult> Update(Guid id, UpdateCustomerDto dto)
 => await _mediator.SendCommand(new UpdateCustomerCommand(id, dto.Name, dto.Email, dto.BirthDate));
 public async Task <IActionResult> updateCustomer(UpdateCustomerDto request)
 {
     return(Ok(await _customerService.updateCustomer(request)));
 }
Beispiel #24
0
 public async Task <UpdateCustomerDto> UpdateCustomerAsync(UpdateCustomerDto updatedCustomer)
 {
     throw new System.NotImplementedException();
 }
Beispiel #25
0
 public IActionResult Put([FromBody] UpdateCustomerDto updateCustomerDto) => base.Put <UpdateCustomerDto, Customer>(updateCustomerDto);
Beispiel #26
0
 public async Task Update(int id, [Required] UpdateCustomerDto dto, CancellationToken cancellationToken)
 {
     await _commandDispatcher.HandleAsync(new UpdateCustomerCommand(id, dto), cancellationToken);
 }
 public async Task Update(UpdateCustomerDto updateCustomerDto)
 {
     var updateEstate = _objectMapper.Map <Customer>(updateCustomerDto);
     await _customerManager.Update(updateEstate);
 }
 public async Task <IActionResult> Update(int id, [FromBody] UpdateCustomerDto dto)
 => await GetResponse(async() =>
                      new ApiResponseViewModel(true, "Customer Updated Successfully",
                                               await _customerService.Update(id, dto, UserId)));
 public async Task <IActionResult> Put([FromRoute] Guid id, [FromBody] UpdateCustomerDto request)
 {
     return(!ModelState.IsValid ? Response(ModelState) : Response(await _customerAppService.Update(id, request)));
 }
Beispiel #30
0
        // Put: CustomerController/Update

        public IActionResult Update([FromBody] UpdateCustomerDto dTO)
        {
            _CustomerService.Update(dTO);
            return(Ok(GetRespons()));
        }