public async Task add_async_with_proper_data_should_create_customer_expect_success() { var customerId = Guid.NewGuid(); var customer = DomainTestsHelper.ValidCustomerWithId(customerId); await customerRepository.AddCustomerAsync(customer); var fetchedCustomer = await customerRepository.GetCustomerAsync(customerId); Assert.Same(customer, fetchedCustomer); }
public async Task <AccountResponse> CreateAccountAsync(AccountRequest request) { var customer = new Customer { CustomerId = Guid.NewGuid(), FirstName = request.FirstName, LastName = request.LastName, Email = request.Email, Address = request.Address }; await customerRepository.AddCustomerAsync(customer); var account = new Account { AccountId = Guid.NewGuid(), CustomerId = customer.CustomerId, AccountIban = request.AccountIban, Balance = request.Balance }; await accountRepository.AddAccountAsync(account); var accountResponse = new AccountResponse { AccountIban = account.AccountIban, Balance = account.Balance }; return(accountResponse); }
public async Task <IActionResult> CreateCustomerCollection( [FromBody] IEnumerable <CustomerCreationDTO> customerCollection) { if (customerCollection == null) { return(BadRequest()); } var customerEntities = Mapper.Map <IEnumerable <Customer> >(customerCollection); foreach (var customer in customerEntities) { await _customerRepository.AddCustomerAsync(customer); } if (!await _customerRepository.SaveAsync()) { throw new Exception("Creating a customer collection failed on save."); } var customersToReturn = Mapper.Map <IEnumerable <CustomerDTO> >(customerEntities); var stringId = string.Join(",", customersToReturn.Select(x => x.Id)); return(CreatedAtRoute("GetCustomerCollection", new { ids = stringId }, customersToReturn)); }
public async Task <ActionResult> SignUp(CustomerViewModel viewModel) { try { //Serverside validation to double check the info provided if (ModelState.IsValid) { curCustName = viewModel.FirstName; curCustphoneNumber = viewModel.PhoneNumber; HttpContext.Session.SetString("PreferredStore", viewModel.storeName.ToString()); var customer = new Customer { FirstName = viewModel.FirstName, LastName = viewModel.LastName, PhoneNumber = viewModel.PhoneNumber, StoreName = viewModel.storeName.ToString(), }; await custRepository.AddCustomerAsync(customer); return(RedirectToAction("Inv", "Customer")); } else { return(View(viewModel)); } } catch (InvalidOperationException e) { ModelState.AddModelError("Invalid Customer Info", e.Message); return(View(viewModel)); } }
public async Task <CustomerResponseDto> AddCustomerAsync(CustomerRequestDto customerDto) { var customer = _mapper.Map <CustomerRequestDto, Customer>(customerDto); var result = await _customerRepository.AddCustomerAsync(customer); return(_mapper.Map <CustomerResponseDto>(result)); }
public async Task <IActionResult> AddCustomerAsync(CustomerViewModel customer) { if (!ModelState.IsValid) { _logger.LogError("Cannot add customer - invalid details"); return(View(nameof(Index))); } int recordsAffected = 0; try { var customerEntity = _mapper.Map <CustomerViewModel, Customer>(customer); recordsAffected = await _repository.AddCustomerAsync(customerEntity); } catch (Exception ex) { _logger.LogError($"Error occured while saving customer - {ex} "); _toastNotification.AddErrorToastMessage(ErrorToast); return(RedirectToAction(nameof(Index))); } if (recordsAffected == 0) { _logger.LogError("No customer was added"); _toastNotification.AddErrorToastMessage(ErrorToast); return(RedirectToAction(nameof(Index))); } _toastNotification.AddSuccessToastMessage(CustomerAddedToast); return(RedirectToAction(nameof(CustomersListAsync))); }
public async Task <Guid> AddCustomerAsync(string firstName, string lastName) { var id = Guid.NewGuid(); await _customerRepository.AddCustomerAsync( new Customer(id, firstName, lastName)); return(id); }
public async Task <CustomerModel> AddCustomerAsync(CustomerModel model) { var customer = _mapper.Map <CustomerModel, Customer>(model); var createdCustomer = await _customerRepository.AddCustomerAsync(customer); return(_mapper.Map <Customer, CustomerModel>(createdCustomer)); }
public async Task <IActionResult> AddCustomer([FromBody] Models.Customer customer) { var customerDto = await customerRepository_.AddCustomerAsync(Map(customer)); var countryDto = await countryRepository_.GetCountryAsync(customerDto.CountryId); return(Ok(Map(customerDto, countryDto.CountryName))); }
public async Task<IActionResult> CreateCustomer([FromBody] CustomerModel customer) { if (!ModelState.IsValid) { return BadRequest(); } await _customerRepository.AddCustomerAsync(customer); return Ok(); }
public async Task <ActionResult <CustomerDto> > AddCustomer([FromBody] Customer customer) { await _repository.AddCustomerAsync(customer); await _repository.CommitAsync(); return(CreatedAtAction(nameof(GetCustomerDetail), new { id = customer.PersonId }, customer.Adapt <CustomerDto> ())); }
public void AddCustomer(String name, String email, String phone, String address) { if (!String.IsNullOrWhiteSpace(name) && !String.IsNullOrWhiteSpace(email) && !String.IsNullOrWhiteSpace(phone) && !String.IsNullOrWhiteSpace(address)) { Customer customer = new Customer(); customer.Name = name; customer.Phone = phone; customer.Address = address; customer.Email = email; _customerRepository.AddCustomerAsync(customer); } else { // Form1.MandatoryfieldsWarning(); } }
public async Task <CustomerViewModel> AddCustomerAsync(AddCustomerViewModel model) { var customerEntity = CustomerMapper.Map(model); var customer = await customerRepository.AddCustomerAsync(customerEntity); var result = CustomerMapper.Map(customer); return(result); }
public async Task <IActionResult> Post([FromBody] CustomerDto customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await customerRepository.AddCustomerAsync(customer); return(Created($"contextapi/customer/{customer.Id}", customer)); }
public async Task <IActionResult> AddCustomerAsync(Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } long customerId = await customerRepository.AddCustomerAsync(customer); customer.Id = customerId; return(CreatedAtAction(nameof(GetCustomerAsync), new { customerId }, customer)); }
public async Task <Customer> CreateCustomerAsync( [Service] IImmutableMapper <CustomerInput, Customer> customerInputToCustomerMapper, [Service] ICustomerRepository customerRepository, CustomerInput customerInput, CancellationToken cancellationToken) { var customer = customerInputToCustomerMapper.Map(customerInput); customer = await customerRepository .AddCustomerAsync(customer, cancellationToken) .ConfigureAwait(false); return(customer); }
public async Task <IActionResult> AddCustomer([FromBody] Customer Customer) { try { var newCustomer = await _repository .AddCustomerAsync(Customer); return(Ok(newCustomer)); } catch (KeyNotFoundException) { return(NotFound()); } }
public async Task AddCustomerAsync(Customer customer) { Customer cust = new Customer() { Firstname = customer.Firstname, Lastname = customer.Lastname, Email = customer.Email, Password = customer.Password, Address = customer.Address, City = customer.City, PostalCode = customer.PostalCode, Telephone = customer.Telephone }; await _customerRepository.AddCustomerAsync(cust); }
private Task <bool> ExecutionAsync(CustomerCreateEvent @event) { var customer = new CustomerInfo() { Id = @event.Id, CustomerCode = @event.CustomerCode, CustomerName = @event.CustomerName, CustomerLevel = @event.CustomerLevel, CreateDate = @event.Timestamp }; _customerRepository.AddCustomerAsync(customer); return(Task.FromResult(true)); }
private async void OnSave() { UpdateCustomer(Customer, _editingCustomer); if (EditMode) { await _repo.UpdateCustomerAsync(_editingCustomer); } else { await _repo.AddCustomerAsync(_editingCustomer); } DoneSaving(); }
public async Task AddCustomerSuccessfully() { var today = DateTime.Now; var totalRecords = _dbContext.Customers.Count(); _customerRepository = new CustomerRepository(_dbContext); var result = await _customerRepository.AddCustomerAsync(new Model.Customer() { FirstName = "Helen", LastName = "Anna", DateOfBirth = today }); var currentRecords = _dbContext.Customers.Count(); Assert.True(result > 0, "Result should be greater than 0"); Assert.Equal(totalRecords + 1, currentRecords); }
public async Task CreateAccountAsync_NewAccountRequest_ReturnAccountResponse() { // Arrange var accountRequest = new AccountRequest { AccountIban = "CCCC", FirstName = "test", LastName = "test", Balance = 1000, Email = "*****@*****.**", Address = "123456" }; var customer = new Customer { CustomerId = Guid.NewGuid(), FirstName = accountRequest.FirstName, LastName = accountRequest.LastName, Email = accountRequest.Email, Address = accountRequest.Address }; var account = new Account { AccountId = Guid.NewGuid(), CustomerId = customer.CustomerId, AccountIban = accountRequest.AccountIban, Balance = accountRequest.Balance }; customerRepository .AddCustomerAsync(Arg.Any <Customer>()) .Returns(Task.FromResult(customer)); accountRepository .GetByAccountIbanAsync(Arg.Any <string>()) .Returns(Task.FromResult(account)); // Act var accountResponse = await customerAccountsService.CreateAccountAsync(accountRequest); // Assert Assert.NotNull(accountResponse); Assert.Equal("CCCC", accountResponse.AccountIban); Assert.Equal(1000, accountResponse.Balance); }
public async Task <CustomerResponseModel> AddNewCustomerAsync(CustomerRequestModel customerRequestModel) { var customer = _mapper.Map <Customer>(customerRequestModel); var bookingRoom = await _roomRepository.GetRoomByIdAsync(customer.RoomNo); var isOccupied = !bookingRoom.Status; if (isOccupied) { throw new ConflictException("The room is occupied!"); } var createdCustomer = await _customerRepository.AddCustomerAsync(customer); bookingRoom.Status = false; await _roomRepository.UpdateRoomAsync(bookingRoom); return(_mapper.Map <CustomerResponseModel>(createdCustomer)); }
private void SaveCustomerInformation(Customer customer) { Customer my = new Customer() { BirthDate = new DateTime(ACustomer.BirthDateYear, ACustomer.BirthDateMonth, ACustomer.BirthDateDay).ToShortDateString(), FirstName = ACustomer.FirstName, LastName = ACustomer.LastName, Gender = ACustomer.Gender, Id = ACustomer.Id, BirthDateDay = ACustomer.BirthDateDay, BirthDateMonth = ACustomer.BirthDateMonth, BirthDateYear = ACustomer.BirthDateYear, Comment = ACustomer.Comment }; if (_EditMode) { _repository.UpdateCustomerAsync(my); } else { my.Id = Guid.NewGuid(); _repository.AddCustomerAsync(my); } foreach (var image in ACustomer.Images) { var filePath = ((BitmapImage)image).UriSource.AbsolutePath; var filename = Path.GetFileName(filePath); var destFolderPath = AppDomain.CurrentDomain.BaseDirectory + @"Images\" + my.Id; if (!Directory.Exists(destFolderPath)) { Directory.CreateDirectory(destFolderPath); } var destFilePath = Path.Combine(destFolderPath, filename); if (!File.Exists(destFilePath)) { File.Copy(filePath, destFilePath); } } SaveCustomerDelegate(); }
private void OnSaveCustomer() { var customer = new Customer() { Id = EditableCustomer.Id, FirstName = EditableCustomer.FirstName, LastName = EditableCustomer.LastName, FavoriteCoffeeType = EditableCustomer.FavoriteCoffeeType }; if (EditableCustomer.Id == default) { _customerRepository.AddCustomerAsync(customer); Customers.Add(customer); } else { _customerRepository.UpdateCustomerAsync(customer); } }
public async Task <CustomerAuthViewModel> RegisterAsync(Customer newCustomer) { var customer = await _customerRepository.AddCustomerAsync(newCustomer); if (customer == null) { return(null); } var claims = new Claim[] { new Claim(ClaimTypes.Name, customer.Email), new Claim("Scope", "Customer") }; var jwtResult = _jwtAuthManager.GenerateTokens(customer.Email, claims, DateTime.Now); return(new CustomerAuthViewModel { Customer = customer, JwtResult = jwtResult }); }
public async Task AddCustomerAsync_AddsCustomerToDatabaseAsync() { // Arrange _repository = new CustomerRepository(GetInMemoryCustomerContext()); var customer = new Customer { FirstName = "Test", LastName = "Customer", DateOfBirth = new DateTime(1991, 1, 2), Email = "*****@*****.**", CustCode = "testcustomer19910102" }; // Act var result = await _repository.AddCustomerAsync(customer).ConfigureAwait(false); var totalCustomers = await _repository.GetAllCustomers().ConfigureAwait(false); // Assert Assert.Single(totalCustomers); }
public async Task <IActionResult> CreateCustomer([FromBody] CustomerCreationDTO customer) { if (customer == null) { return(BadRequest()); } var customerEntity = Mapper.Map <Customer>(customer); await _customerRepository.AddCustomerAsync(customerEntity); if (!await _customerRepository.SaveAsync()) { throw new Exception("Creating a customer failed on save"); } var customerToReturn = Mapper.Map <CustomerDTO>(customerEntity); return(CreatedAtRoute("GetCustomer", new { id = customerToReturn.Id }, customerToReturn)); }
public async Task <IActionResult> AddCustomer([FromBody] Customer customer) { await _customerRepo.AddCustomerAsync(customer); return(Ok(customer)); }
public async Task <IActionResult> AddCustomer([FromBody] CustomersClass model) { var result = await _repo.AddCustomerAsync(model); return(Ok(result)); }