public async Task SendTreatmentReportAsync(CustomerTreatment treatment)
        {
            HttpContent content  = new StringContent(JsonConvert.SerializeObject(treatment), Encoding.UTF8, "application/json");
            var         response = await client.PostAsync($"{ConstantURI.usersServerURI}Users/customers/history", content);

            response.EnsureSuccessStatusCode();
        }
Exemplo n.º 2
0
        public async Task SaveCustomerTreatment(CustomerTreatment customerTreatment)
        {
            Treatment treatment = new Treatment
            {
                CustomerId    = customerTreatment.CustomerId,
                EmployeeId    = customerTreatment.TreatingEmployeeId,
                TreatmentDate = customerTreatment.DateOfTreatment.Date
            };

            _usersContext.Treatments.Add(treatment);
            await _usersContext.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PostCustomerTreatment([FromBody] CustomerTreatment customerTreatment)
        {
            try
            {
                await _usersService.SaveCustomerTreatment(customerTreatment);

                return(CreatedAtAction(nameof(PostCustomerTreatment), customerTreatment));
            }
            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 Task ReportTretment(CustomerTreatment treatment)
        {
            TreatmentMock mock = new TreatmentMock()
            {
                Customer = new CustomerMock()
                {
                    CustomerId = treatment.CustomerId
                },
                EmployeeId    = treatment.TreatingEmployeeId,
                TreatmentDate = DateTime.Now
            };

            if (treatmentMocks.Contains(mock))
            {
                throw new Exception();
            }

            treatmentMocks.Add(mock);

            return(Task.FromResult(mock));
        }
        public async Task SaveCustomerTreatment_SaveOneTreatment_TreatmentInDb()
        {
            using (UsersContext context = GetUsersContext())
            {
                int      employeeId = 11;
                int      customerId = 1;
                DateTime today      = DateTime.Today;
                Customer customer   = new Customer {
                    CustomerId = customerId, CardNumber = 100
                };
                Employee employee = new Employee {
                    EmployeeId = employeeId
                };
                context.Customers.Add(customer);
                context.Employees.Add(employee);
                context.SaveChanges();
                CustomerTreatment customerTreatment = new CustomerTreatment
                {
                    CustomerId         = customerId,
                    DateOfTreatment    = today,
                    TreatingEmployeeId = employeeId
                };
                Treatment expectedTreatment = new Treatment
                {
                    EmployeeId    = employeeId,
                    CustomerId    = customerId,
                    TreatmentDate = today,
                    Customer      = customer,
                    Employee      = employee
                };

                Services.UsersService usersService = new Services.UsersService(context, GetQueueApiServiceMock());
                await usersService.SaveCustomerTreatment(customerTreatment);

                Treatment actualTreatment = context.Treatments.Find(today, customerId, employeeId);
                Assert.AreEqual(expectedTreatment.TreatmentDate, actualTreatment.TreatmentDate);
                Assert.AreEqual(expectedTreatment.EmployeeId, actualTreatment.EmployeeId);
                Assert.AreEqual(expectedTreatment.CustomerId, actualTreatment.CustomerId);
            }
        }
        public async Task PostCustomerTreatment_PostValidTreatment_TreatmentSavedAndDateTruncated()
        {
            using (var context = GetInitializedUsersContext())
            {
                var               usersService = new Services.UsersService(context, new QueueApiServiceMock());
                UsersController   controller   = new UsersController(usersService);
                CustomerTreatment treatment    = new CustomerTreatment
                {
                    CustomerId         = 10,
                    DateOfTreatment    = DateTime.Now,
                    TreatingEmployeeId = 3
                };

                IActionResult result = await controller.PostCustomerTreatment(treatment);

                Assert.IsInstanceOf <IActionResult>(result);
                Assert.IsInstanceOf <CreatedAtActionResult>(result);
                Assert.DoesNotThrow(() => context.Treatments.
                                    Where(t => t.CustomerId == treatment.CustomerId && t.TreatmentDate == DateTime.Today && t.EmployeeId == treatment.TreatingEmployeeId).
                                    Single());
            }
        }
Exemplo n.º 7
0
        async void ExecuteCallNextCommandAsync()
        {
            try
            {
                DequeuePosition dequeuePosition = new DequeuePosition()
                {
                    ServiceType = Model.StationServiceType, StationNumber = Model.StationNumber
                };

                DequeuePositionResult result = await http.CallNextInQueueAsync(dequeuePosition);

                if (result == null)
                {
                    dialog.ShowMessage("There are no client wating for treatment");
                    return;
                }

                DequeueModel.CustomerId   = result.CustomerID;
                DequeueModel.QueueuNumber = result.CustomerNumberInQueue;

                // Send last client as a treatment report
                if (DequeueModel.CustomerId > 0)
                {
                    CustomerTreatment treatment = new CustomerTreatment()
                    {
                        CustomerId         = DequeueModel.CustomerId,
                        TreatingEmployeeId = Model.EmployeeId,
                        DateOfTreatment    = DateTime.Now
                    };
                    await http.SendTreatmentReportAsync(treatment);
                }
            }
            catch (Exception e)
            {
                dialog.ShowMessage(e.Message);
            }
        }
Exemplo n.º 8
0
 public async Task SendTreatmentReportAsync(CustomerTreatment treatment)
 {
     await mockRepository.ReportTretment(treatment);
 }