예제 #1
0
        public async Task <ActionResult <IPracticePlan> > PostAsync(PracticePlanDto practicePlan)
        {
            var newPracticePlan = await this.practicePlanRepository.UpsertAsync(practicePlan);

            return(this.CreatedAtAction(
                       nameof(this.GetAsync),
                       new { startDate = newPracticePlan.StartDate },
                       newPracticePlan));
        }
예제 #2
0
        public async Task <ActionResult> PutAsync(DateTimeOffset startDate, PracticePlanDto practicePlan)
        {
            var practicePlanToUpdate = await this.practicePlanRepository.GetAsync(startDate);

            if (practicePlanToUpdate == null)
            {
                return(this.NotFound());
            }

            practicePlanToUpdate.Details = practicePlan.Details;

            await this.practicePlanRepository.UpsertAsync(practicePlanToUpdate);

            return(this.NoContent());
        }
예제 #3
0
        private static async Task Main(string[] args)
        {
            var exitCode = 0;

            try
            {
                BindConfigurationOptions();
                ConfigureServices();
                ConfigureLogging();

                logger.Information("Starting {applicationTitle}...", ApplicationTitle);

                var serviceProvider        = services.BuildServiceProvider();
                var practicePlanRepository = serviceProvider.GetService <IPracticePlanRepository>();

                DateTimeOffset startDate    = new DateTimeOffset(2018, 9, 25, 0, 0, 0, 0, new TimeSpan());
                var            practicePlan = new PracticePlanDto {
                    StartDate = startDate
                };

                logger.Information("Upserting practice plan with start date {startDate:yyyy-MM-dd}", practicePlan.StartDate);
                await practicePlanRepository.UpsertAsync(practicePlan);

                var fetchedPlan = await practicePlanRepository.GetAsync(startDate);

                logger.Information("Fetched practice plan with start date {startDate:yyyy-MM-dd}", fetchedPlan.StartDate);

                fetchedPlan.StartDate = startDate.AddDays(1);
                logger.Information("Updating the start date to {startDate:yyyy-MM-dd}", fetchedPlan.StartDate);
                await practicePlanRepository.UpsertAsync(fetchedPlan);

                fetchedPlan = await practicePlanRepository.GetAsync(fetchedPlan.StartDate);

                logger.Information("Fetched updated practice plan with start date {startDate:yyyy-MM-dd}", fetchedPlan.StartDate);

                var planToDelete = new PracticePlanDto {
                    StartDate = startDate
                };
                logger.Information("Deleting the plan with start date {startDate:yyyy-MM-dd}", planToDelete.StartDate);
                await practicePlanRepository.DeleteAsync(planToDelete);

                fetchedPlan = await practicePlanRepository.GetAsync(startDate);

                if (fetchedPlan == null)
                {
                    logger.Information("No practice plan exists with start date {startDate:yyyy-MM-dd}", startDate);
                }
                else
                {
                    logger.Information("Fetched practice plan with start date {startDate:yyyy-MM-dd}", fetchedPlan.StartDate);
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(ex, "An unhandled exception has occurred!");
                exitCode = -1;
            }

            logger.Information("Exiting {applicationTitle} with exit code {exitCode}...", ApplicationTitle, exitCode);
            Log.CloseAndFlush();

            Environment.Exit(exitCode);
        }