Пример #1
0
        protected override async Task <bool> SaveAsync()
        {
            var monthIndex = dateTimeService.GetGenitiveMonthIndex(SelectedMonth) + 1;

            var timeArray = Time.Split(':');
            var hours     = int.Parse(timeArray[0]);
            var minutes   = int.Parse(timeArray[1]);

            var dateTime = new DateTime(SelectedYear, monthIndex, SelectedDay, hours, minutes, 0);

            if (Enrollment is null)
            {
                Enrollment = await enrollmentService.AddEnrollmentAsync(new Enrollment()
                {
                    ClientFirstname   = ClientFirstname,
                    ClientPhoneNumber = ClientPhoneNumber,
                    DateTime          = dateTime,
                    Description       = Description,
                    CreationDateTime  = DateTime.Now
                });
            }
            else
            {
                Enrollment.ClientFirstname   = ClientFirstname;
                Enrollment.ClientPhoneNumber = ClientPhoneNumber;
                Enrollment.DateTime          = dateTime;
                Enrollment.Description       = Description;
                Enrollment.EditDateTime      = DateTime.Now;

                await enrollmentService.EditEnrollmentAsync(Enrollment);

                await serviceManager.RemoveAllEnrollmentWorkerServicesAsync(Enrollment.Id);
            }

            var enrollmentWorkerServices = new List <EnrollmentWorkerService>();

            EnrollmentServices.ForEach(EnrollmentService =>
            {
                enrollmentWorkerServices.Add(new EnrollmentWorkerService()
                {
                    EnrollmentId = Enrollment.Id,
                    ServiceId    = EnrollmentService.Id,
                    WorkerId     = EnrollmentService.WorkerId
                });
            });

            await serviceManager.AddEnrollmentWorkerServicesAsync(enrollmentWorkerServices);

            return(await base.SaveAsync());
        }