public async Task <IActionResult> PutCustomerIdentification(int id, CustomerIdentification customerIdentification) { if (id != customerIdentification.CustomerUniqueId) { return(BadRequest()); } _context.Entry(customerIdentification).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerIdentificationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <CustomerIdentification> GetCustomerIdentification(ulong cardId) { Customer customer = await _usersContext.Customers.Where(c => c.CardNumber == cardId).SingleOrDefaultAsync(); CustomerIdentification customerIdentification = new CustomerIdentification(); if (customer != null) { customerIdentification.CustomerId = customer.CustomerId; } return(customerIdentification); }
/* * Call the users api for the validation of the client card */ public async Task <CustomerIdentification> ValidateCustomerAsync(CardInfo cardInfo) { CustomerIdentification respone = new CustomerIdentification(); HttpResponseMessage httpResponse = await client.GetAsync($"{ConstantURI.usersServerURI}Users/customers/authentication/{cardInfo.CardNumber.ToString()}"); httpResponse.EnsureSuccessStatusCode(); respone = await httpResponse.Content.ReadAsAsync <CustomerIdentification>(); return(respone); }
public async Task <ActionResult <CustomerIdentification> > GetCustomerId(ulong cardNumber) { try { CustomerIdentification customer = await _usersService.GetCustomerIdentification(cardNumber); if (customer.CustomerId == default) { return(NotFound(cardNumber)); } return(customer); } catch (Exception e) { return(BadRequest(e)); // Not best practice to return any exception data, but we don't have and don't need loggers. } }
public async Task GetCustomerIdentification_PassCardNumber_ReturnsCustomerId() { using (UsersContext context = GetUsersContext()) { ulong cardId = 2; int expectedCustomerId = 1; context.Customers.Add(new Customer { CardNumber = cardId, CustomerId = expectedCustomerId }); context.SaveChanges(); Services.UsersService usersService = new Services.UsersService(context, GetQueueApiServiceMock()); CustomerIdentification customerIdentification = await usersService.GetCustomerIdentification(cardId); int actualCustomerId = customerIdentification.CustomerId; Assert.AreEqual(expectedCustomerId, actualCustomerId); } }
/* * Simulate card swiping and connecting to the user api to check on the guid of the customer */ private async void ExecuteSendValidateCommandAsync() { Customer.ClientCard = new CardInfo() { CardNumber = SelectedUser }; try { CustomerIdentification customer = await httpActions.ValidateCustomerAsync(Customer.ClientCard); Customer.CustomerID = customer.CustomerId; _ea?.GetEvent <ChangeViewEvent>().Publish(ViewType.select); _ea?.GetEvent <SendPatientEvent>().Publish(Customer); } catch (HttpRequestException e) { views.ShowErrorDialog(e.Message); } }
public async Task <ActionResult <CustomerIdentification> > PostCustomerIdentification(CustomerIdentification customerIdentification) { _context.customerIdentifications.Add(customerIdentification); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCustomerIdentification", new { id = customerIdentification.CustomerUniqueId }, customerIdentification)); }