Esempio n. 1
0
        public async Task <(bool success, string?message, TravelPlan?travelPlan)> CreateTravelPlan(
            TravelPlanOptions travelPlanOptions)
        {
            var(success, carUnavailableMessage) = await _carService.IsCarAvailable(travelPlanOptions.Adapt <IsCarAvailableOptions>());

            if (!success)
            {
                return(false, carUnavailableMessage, null);
            }

            var(areEmployeesAvailable, errorMessage) = await _employeeService.AreEmployeesAvailable(travelPlanOptions.EmployeeIds,
                                                                                                    travelPlanOptions.StartDateUtc, travelPlanOptions.EndDateUtc);

            if (!areEmployeesAvailable)
            {
                return(false, errorMessage, null);
            }

            var travelPlan = new TravelPlan()
            {
                CarId               = travelPlanOptions.CarId,
                StartLocationId     = travelPlanOptions.StartLocationId,
                EndLocationId       = travelPlanOptions.EndLocationId,
                StartTimeUtc        = travelPlanOptions.StartDateUtc,
                EndTimeUtc          = travelPlanOptions.EndDateUtc,
                TravelPlanEmployees = new List <TravelPlanEmployees>()
            };

            foreach (var employeeId in travelPlanOptions.EmployeeIds)
            {
                travelPlan.TravelPlanEmployees.Add(new TravelPlanEmployees()
                {
                    EmployeeId = employeeId,
                });
            }


            await _dbContext.TravelPlans.AddAsync(travelPlan);

            await _dbContext.SaveChangesAsync();

            return(true, null, travelPlan);
        }
Esempio n. 2
0
 public async Task Commit()
 {
     await context.SaveChangesAsync();
 }