Exemple #1
0
        public async Task <IActionResult> ChangeEmailSchedule(NextScheduleModel nextScheduleModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            await this.adminService.ChangeNextProductSchedule(nextScheduleModel);

            return(RedirectToAction("ChangeEmailTimer"));
        }
        public async Task ChangeNextProductSchedule(NextScheduleModel nextScheduleModel)
        {
            var currentSchedule = this.context.NextProductsSchedule.FirstOrDefault();

            var requisitions = await this.context.Requisitions.Where(x => x.ScheduleFor == currentSchedule.NextSchedule).ToListAsync();

            for (int i = 0; i < requisitions.Count; i++)
            {
                requisitions[i].ScheduleFor = nextScheduleModel.NextSchedule;
                this.context.Requisitions.Update(requisitions[i]);
            }

            currentSchedule.NextSchedule = nextScheduleModel.NextSchedule;
            this.context.NextProductsSchedule.Update(currentSchedule);
            await this.context.SaveChangesAsync();
        }