Пример #1
0
        public async Task <IActionResult> EditSchedule(ScheduleViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(await ScheduleViewModel.ReBuildForEditAsync(model, this.ScheduleSevice)));
            }

            var schedules = await this.SchedulerWorkData.Schedules.FindAsync(s => s.Id == model.Id, i => i.Include(x => x.Employee));

            var schedule = schedules.FirstOrDefault();

            if (schedule == null)
            {
                ModelState.AddModelError(
                    string.Empty,
                    $"Schedule to edit not found. Please try again and if the problem persist contact the administrator.");

                return(View(await ScheduleViewModel.ReBuildForEditAsync(model, this.ScheduleSevice)));
            }

            schedule.Update(model.WorkHours, model.ExtraWorkHours, model.ScheduleOption, model.ProjectId);
            await this.SchedulerWorkData.CompleteAsync();

            return(RedirectToAction(nameof(EmployeesScheduler)));
        }