public async Task ApproveAppointmentRequestAsync(ApproveAppointmentRequestModel model) { var appointment = await _dbContext.Appointments.FindAsync(model.Id); if (appointment == null || string.IsNullOrEmpty(appointment.Description) || !appointment.Description.Contains("#Requested")) { throw new AwroNoreException("Appointment request not found"); } if (appointment.Status != AppointmentStatus.Unknown) { throw new AwroNoreException("This appointment request approved before"); } var strategy = _dbContext.Database.CreateExecutionStrategy(); await strategy.ExecuteAsync(async() => { using (var transaction = _dbContext.Database.BeginTransaction()) { appointment.Status = AppointmentStatus.Pending; appointment.Start_DateTime = DateTime.Parse($"{model.Date.Date.ToShortDateString()} {model.StartTime}"); appointment.End_DateTime = DateTime.Parse($"{model.Date.Date.ToShortDateString()} {model.EndTime}"); _appointmentRepository.Update(appointment); if (model.SendNotification) { if (appointment.Person.FcmInstanceIds != null && appointment.Person.FcmInstanceIds.Any()) { var donePayload = new DoneAppointmentNotificationPayload { AppointmentId = appointment.Id, NotificationType = NotificationType.AppointmentAccepted }; foreach (var item in appointment.Person.FcmInstanceIds) { var title = "Accept Appointment"; var message = "Your appointment has been accepted"; await _notificationService.SendFcmToSingleDeviceAsync(item.InstanceId, title, message); } } } transaction.Commit(); } }); }
private async Task SendDoneAppointmentNotificationAsync(Appointment appointment, Patient patient) { if (appointment.Person.FcmInstanceIds != null && appointment.Person.FcmInstanceIds.Any()) { var donePayload = new DoneAppointmentNotificationPayload { AppointmentId = appointment.Id, NotificationType = NotificationType.AppointmentDone, UserTurnItem = new Core.DTO.Turn.UserTurnItemDTO { Id = appointment.Id, ServiceSupplyId = appointment.ServiceSupplyId, Date = appointment.Start_DateTime.ToShortDateString(), StartTime = appointment.Start_DateTime.ToShortTimeString(), EndTime = appointment.End_DateTime.ToShortTimeString(), Status = appointment.Status, DoctorName = Lng == Lang.KU ? appointment.ServiceSupply.Person.FullName_Ku : Lng == Lang.AR ? appointment.ServiceSupply.Person.FullName_Ar : appointment.ServiceSupply.Person.FullName, DayOfWeek = Utils.ConvertDayOfWeek(appointment.Start_DateTime.DayOfWeek.ToString()), IsRated = appointment.Rate != null, AverageRating = (appointment.Rate != null) ? appointment.Rate.Rating : 5, TrackingCode = appointment.UniqueTrackingCode, CenterServiceId = appointment.ShiftCenterServiceId, Service = Lng == Lang.KU ? appointment.ShiftCenterService.Service.Name_Ku : Lng == Lang.AR ? appointment.ShiftCenterService.Service.Name_Ar : appointment.ShiftCenterService.Service.Name } }; var enCulture = new CultureInfo(SupportedLangs.EN); var arCulture = new CultureInfo(SupportedLangs.AR); var kuCulture = new CultureInfo(SupportedLangs.KU); var basePayload = new BaseNotificationPayload { Title = Messages.ResourceManager.GetString("AppointmentDoneNotificationTitle", enCulture), TitleKu = Messages.ResourceManager.GetString("AppointmentDoneNotificationTitle", kuCulture), TitleAr = Messages.ResourceManager.GetString("AppointmentDoneNotificationTitle", arCulture), Body = Messages.ResourceManager.GetString("AppointmentDoneNotificationBody", enCulture), BodyKu = Messages.ResourceManager.GetString("AppointmentDoneNotificationBody", kuCulture), BodyAr = Messages.ResourceManager.GetString("AppointmentDoneNotificationBody", arCulture) }; foreach (var item in patient.Person.FcmInstanceIds) { await _notificationService.SendDoneAppointmentNotificationAsync(item.InstanceId, basePayload, donePayload); } } }