public async Task <AppointmentChangeRequest> CreateAppointmentChangeRequest(DateTime start, DateTime end, Appointment appointment, DateTime timestamp, string message) { var appointmentChangeRequest = new AppointmentChangeRequest(); await using var context = ContextFactory.CreateDbContext(); var createdAppointmentChangeRequest = (await context.AppointmentChangeRequests.AddAsync(appointmentChangeRequest)).Entity; await context.SaveChangesAsync(); createdAppointmentChangeRequest.IsActive = true; createdAppointmentChangeRequest.NewStartDateTime = start; createdAppointmentChangeRequest.NewEndDateTime = end; createdAppointmentChangeRequest.IsApproved = false; createdAppointmentChangeRequest.Appointment = appointment; createdAppointmentChangeRequest.PreviousStartDateTime = appointment.StartDateTime; createdAppointmentChangeRequest.PreviousEndDateTime = appointment.EndDateTime; await using var context1 = ContextFactory.CreateDbContext(); context.AppointmentChangeRequests.Update(createdAppointmentChangeRequest); await context.SaveChangesAsync(); await _notificationService.PublishAppointmentChangeRequestNotification(appointmentChangeRequest, timestamp, message); return(createdAppointmentChangeRequest); }
public async Task <AppointmentChangeRequestNotification> PublishAppointmentChangeRequestNotification(AppointmentChangeRequest appointmentChangeRequest, DateTime timestamp, string message) { var notification = new AppointmentChangeRequestNotification(); await Create(notification); notification.IsActive = true; notification.AppointmentChangeRequest = appointmentChangeRequest; notification.Timestamp = timestamp; notification.Status = NotificationStatus.Unread; notification.Message = message; return(await Update(notification) as AppointmentChangeRequestNotification); }