Пример #1
0
        public void Update(mp_appointment_refund refund)
        {
            var old = _context.mp_appointment_refund.FirstOrDefault(e => e.id == refund.id);

            refund.created_at = DateTime.Now;
            refund.created_by = refund.created_by;

            _context.Entry(old).CurrentValues.SetValues(refund);
            _context.SaveChanges();
        }
Пример #2
0
        public async Task <ActionResult> Refund(string appointmentid)
        {
            try
            {
                var appointment_id = Guid.Parse(appointmentid);
                var appointment    = _appointmentService.Get().Include(e => e.mp_credit)
                                     .Include(e => e.client_).Include(e => e.clinician_).FirstOrDefault(e => e.id == appointment_id);

                if (appointment.status != 169 && appointment.status != 234)
                {
                    return(Ok("This appointment cannot be cancelled."));
                }

                var user_notification = "An appointment that you created was cancelled.";

                Guid logged_user_id = Guid.Parse(_userManager.GetUserId(HttpContext.User));
                var  cancelled_by   = 298;
                var  profile        = _profileService.GetByUserId(logged_user_id);

                //check if payment has been made for the appointment
                if (appointment.mp_credit.Any() && appointment.status != 171)
                {
                    var creditInfo = appointment.mp_credit.FirstOrDefault(x => x.appointment_id == appointment.id);
                    if (creditInfo != null)
                    {
                        var resundResponse = new PayStackHelper(_payStackSettings).Refund(creditInfo.transaction_reference);
                        if (resundResponse)
                        {
                            user_notification += " Your payment will be processed shortly and you will get it back in the next 24 - 48 hours.";
                            //refund the client
                            var refund = new mp_appointment_refund
                            {
                                appointment_id = appointment_id,
                                created_by     = logged_user_id.ToString(),
                                amount         = appointment.mp_credit.FirstOrDefault().amount,
                                cancelled_by   = cancelled_by,
                                status         = 296
                            };

                            _appointmentRefundService.AddRefund(refund);
                        }
                    }
                }

                appointment.status        = 171;
                appointment.cancelled_by  = appointment.clinician_id;
                appointment.cancel_reason = "Cancel and Refund";

                _appointmentService.Update(appointment);
                //notifications to the client and the clinician

                var notification = new mp_notification
                {
                    created_by        = "sys_admin",
                    created_by_name   = "System Admin",
                    notification_type = 5,
                    read         = 0,
                    user_id      = appointment.client_.user_id,
                    notification = "Hi " + appointment.client_.last_name + " " + appointment.client_.first_name + ", " + user_notification,
                    title        = "Appointment cancelled"
                };

                NotificationUtil.Add(notification);

                await _emailSender.SendEmailAsync(appointment.client_.email, "Appointment cancelled - MySpace MyTime",
                                                  $"Hi " + appointment.client_.last_name + " " + appointment.client_.first_name + ", " + user_notification);


                notification = new mp_notification
                {
                    created_by        = "sys_admin",
                    created_by_name   = "System Admin",
                    notification_type = 5,
                    read         = 0,
                    user_id      = appointment.clinician_.user_id,
                    notification = "Hi " + appointment.clinician_.last_name + " " + appointment.clinician_.first_name + ", an appointment scheduled with you have been cancelled.",
                    title        = "Appointment cancelled"
                };

                NotificationUtil.Add(notification);
                await _emailSender.SendEmailAsync(appointment.clinician_.email, "Appointment cancelled - MySpace MyTime",
                                                  $"Hi " + appointment.clinician_.last_name + " " + appointment.clinician_.first_name + ", an appointment scheduled with you have been cancelled.");

                return(Ok(200));
            }
            catch (Exception ex)
            {
                return(Ok(ex.Message));
            }
        }
Пример #3
0
        public async Task CancelBySystem(string appointmentid)
        {
            Guid logged_user_id = Guid.Parse(_userManager.GetUserId(HttpContext.User));
            var  cancelReason   = string.Empty;
            var  appointment_id = Guid.Parse(appointmentid);
            var  appointment    = _appointmentService.Get().Include(e => e.mp_credit)
                                  .Include(e => e.client_).Include(e => e.clinician_).FirstOrDefault(e => e.id == appointment_id);

            if (appointment.status == 234)
            {
                var  user_notification = "An appointment that you created was cancelled.";
                var  cancelled_by      = 298;
                var  profile           = _profileService.GetByUserId(logged_user_id);
                Guid?cancelById        = null;
                if (User.IsInRole("client"))
                {
                    var user_profile = _profileService.GetByUserId(logged_user_id);
                    var bank         = _profileBankService.GetProfileBank(user_profile.id);
                    if (bank == null)
                    {
                        bank = new mp_profile_bank();
                    }
                    cancelled_by    = 297;
                    bank.updated_by = logged_user_id.ToString();
                    bank.created_by = logged_user_id.ToString();
                    bank.profile_id = profile.id;
                    cancelById      = appointment.client_id;
                    _profileBankService.AddOrUpdate(bank);
                    cancelReason = "Clinician not avilable on time.";
                }
                if (User.IsInRole("clinician"))
                {
                    cancelById   = appointment.clinician_id;
                    cancelReason = "Client not avilable on time.";
                }

                //check if payment has been made for the appointment
                if (appointment.mp_credit.Any() && appointment.status != 171 && User.IsInRole("clinician"))
                {
                    var creditInfo = appointment.mp_credit.FirstOrDefault(x => x.appointment_id == appointment.id);
                    if (creditInfo != null)
                    {
                        var resundResponse = new PayStackHelper(_payStackSettings).Refund(creditInfo.transaction_reference);
                        if (resundResponse)
                        {
                            user_notification += " Your payment will be processed shortly and you will get it back in the next 24 - 48 hours.";
                            //refund the client
                            var refund = new mp_appointment_refund
                            {
                                appointment_id = appointment_id,
                                created_by     = logged_user_id.ToString(),
                                amount         = appointment.mp_credit.FirstOrDefault().amount,
                                cancelled_by   = cancelled_by,
                                status         = 296
                            };

                            _appointmentRefundService.AddRefund(refund);
                        }
                    }
                }

                appointment.status        = 171;
                appointment.cancelled_by  = cancelById;
                appointment.cancel_reason = cancelReason;
                _appointmentService.Update(appointment);
                //notifications to the client and the clinician

                var notification = new mp_notification
                {
                    created_by        = "sys_admin",
                    created_by_name   = "System Admin",
                    notification_type = 5,
                    read         = 0,
                    user_id      = appointment.client_.user_id,
                    notification = "Hi " + appointment.client_.last_name + " " + appointment.client_.first_name + ", " + user_notification + ", due to " + cancelReason,
                    title        = "Appointment cancelled"
                };

                NotificationUtil.Add(notification);

                await _emailSender.SendEmailAsync(appointment.client_.email, "Appointment cancelled - MySpace MyTime",
                                                  $"Hi " + appointment.client_.last_name + " " + appointment.client_.first_name + ", " + user_notification + ", due to " + cancelReason);


                notification = new mp_notification
                {
                    created_by        = "sys_admin",
                    created_by_name   = "System Admin",
                    notification_type = 5,
                    read         = 0,
                    user_id      = appointment.clinician_.user_id,
                    notification = "Hi " + appointment.clinician_.last_name + " " + appointment.clinician_.first_name + ", an appointment scheduled with you have been cancelled." + ", due to " + cancelReason,
                    title        = "Appointment cancelled"
                };

                NotificationUtil.Add(notification);
                await _emailSender.SendEmailAsync(appointment.clinician_.email, "Appointment cancelled - MySpace MyTime",
                                                  $"Hi " + appointment.clinician_.last_name + " " + appointment.clinician_.first_name + ", an appointment scheduled with you have been cancelled" + ", due to " + cancelReason);
            }
        }
Пример #4
0
        public async Task <IActionResult> Cancel(mp_profile_bank bank)
        {
            var collection     = Request.Form;
            var appointment_id = Guid.Parse(collection["appointment_id"]);
            var appointment    = _appointmentService.Get().Include(e => e.mp_credit).Include(e => e.client_).Include(e => e.clinician_).FirstOrDefault(e => e.id == appointment_id);

            if (appointment.status != 169 && appointment.status != 234)
            {
                TempData["AlertType"]    = "alert-warning";
                TempData["AlertMessage"] = "This appointment cannot be cancelled.";
                return(RedirectToAction("Details", new { id = appointment_id }));
            }

            var user_notification = "An appointment that you created was cancelled.";


            Guid logged_user_id = Guid.Parse(_userManager.GetUserId(HttpContext.User));
            var  cancelled_by   = 298;
            var  profile        = _profileService.GetByUserId(logged_user_id);
            Guid?cancelById     = null;

            if (User.IsInRole("client"))
            {
                cancelled_by    = 297;
                bank.updated_by = logged_user_id.ToString();
                bank.created_by = logged_user_id.ToString();
                bank.profile_id = profile.id;
                cancelById      = appointment.client_id;
                _profileBankService.AddOrUpdate(bank);
            }
            if (User.IsInRole("clinician"))
            {
                cancelById = appointment.clinician_id;
            }

            //check if payment has been made for the appointment
            if (appointment.mp_credit.Any() && appointment.status != 171)
            {
                var creditInfo = appointment.mp_credit.FirstOrDefault(x => x.appointment_id == appointment.id);
                if (creditInfo != null)
                {
                    var resundResponse = new PayStackHelper(_payStackSettings).Refund(creditInfo.transaction_reference);
                    if (resundResponse)
                    {
                        user_notification += " Your payment will be processed shortly and you will get it back in the next 24 - 48 hours.";
                        //refund the client
                        var refund = new mp_appointment_refund
                        {
                            appointment_id = appointment_id,
                            created_by     = logged_user_id.ToString(),
                            amount         = appointment.mp_credit.FirstOrDefault().amount,
                            cancelled_by   = cancelled_by,
                            status         = 296
                        };

                        _appointmentRefundService.AddRefund(refund);
                    }
                }
            }

            appointment.status        = 171;
            appointment.cancelled_by  = cancelById;
            appointment.cancel_reason = collection["comment"];

            _appointmentService.Update(appointment);
            //notifications to the client and the clinician

            var notification = new mp_notification
            {
                created_by        = "sys_admin",
                created_by_name   = "System Admin",
                notification_type = 5,
                read         = 0,
                user_id      = appointment.client_.user_id,
                notification = "Hi " + appointment.client_.last_name + " " + appointment.client_.first_name + ", " + user_notification,
                title        = "Appointment cancelled"
            };

            NotificationUtil.Add(notification);

            await _emailSender.SendEmailAsync(appointment.client_.email, "Appointment cancelled - MySpace MyTime",
                                              $"Hi " + appointment.client_.last_name + " " + appointment.client_.first_name + ", " + user_notification);


            notification = new mp_notification
            {
                created_by        = "sys_admin",
                created_by_name   = "System Admin",
                notification_type = 5,
                read         = 0,
                user_id      = appointment.clinician_.user_id,
                notification = "Hi " + appointment.clinician_.last_name + " " + appointment.clinician_.first_name + ", an appointment scheduled with you have been cancelled.",
                title        = "Appointment cancelled"
            };



            NotificationUtil.Add(notification);

            await _emailSender.SendEmailAsync(appointment.clinician_.email, "Appointment cancelled - MySpace MyTime",
                                              $"Hi " + appointment.clinician_.last_name + " " + appointment.clinician_.first_name + ", an appointment scheduled with you have been cancelled.");



            return(RedirectToAction("CancelConfirmation"));
        }
Пример #5
0
 public void AddRefund(mp_appointment_refund refund)
 {
     refund.created_at = DateTime.Now;
     _context.mp_appointment_refund.Add(refund);
     _context.SaveChanges();
 }