예제 #1
0
        public IHttpActionResult ApproveCancelBooking(PatientBookingModel model)
        {
            try
            {
                var UserId  = ((ClaimsIdentity)User.Identity).Claims.FirstOrDefault(c => c.Type.Equals(ClaimTypes.NameIdentifier)).Value;
                var RefType = ((ClaimsIdentity)User.Identity).Claims.FirstOrDefault(c => c.Type.Equals(ClaimTypes.Name)).Value;
                var RefID   = ((ClaimsIdentity)User.Identity).Claims.FirstOrDefault(c => c.Type.Equals(ClaimTypes.Sid)).Value;

                BookingDL obj = new BookingDL();
                obj.ApproveCancelBooking(model);
                model.success = true;
                model.message = "Booking " + model.Status + " successfully";
                model.code    = 200;

                //For Therapist
                if (model.Status == "APPROVED")
                {
                    SendMail   mail = new SendMail();
                    RegisterDL obj1 = new RegisterDL();

                    var getBooking = entities.PatientBookings.Where(x => x.PatientBookingID == model.PatientBookingID).FirstOrDefault();

                    var getUserTherapist = entities.Therapists.Where(x => x.TherapistID == getBooking.TherapistID).FirstOrDefault();

                    var getUserPatient = entities.Patients.Where(x => x.PatientID == getBooking.PatientID).FirstOrDefault();

                    var getUserTherapistEmail = entities.Users.Where(x => x.RefID == getUserTherapist.TherapistID && x.RefType == 1).FirstOrDefault();

                    var getUserPatientEmail = entities.Users.Where(x => x.RefID == getUserPatient.PatientID && x.RefType == 2).FirstOrDefault();

                    var services = (from ep in entities.Services
                                    join e in entities.PatientBookings on ep.ServiceID equals e.ServiceID
                                    where e.PatientBookingID == model.PatientBookingID
                                    select new
                    {
                        ServiceName = ep.ServiceName
                    }).ToList();

                    string getServiceName = "";
                    foreach (var item in services)
                    {
                        getServiceName += item.ServiceName + ",";
                    }
                    getServiceName = getServiceName.TrimEnd(',');


                    string bookingDate = getBooking.BookingDate?.DayOfWeek.ToString() + " " + getBooking.BookingDate?.ToString("MMMM") + " " + getBooking.BookingDate?.Day + " " + getBooking.BookingDate?.Year;



                    //For Therapist
                    string body = mail.createEmailBody("TherapistBookingConfirmation.html");
                    body = body.Replace("{PatientName}", getUserPatient.FirstName + " " + getUserPatient.LastName);
                    body = body.Replace("{UserName}", getUserTherapist.FirstName + " " + getUserTherapist.LastName);
                    body = body.Replace("{PatientAddress}", getBooking.Address);

                    body = body.Replace("{PatientServices}", getServiceName);
                    body = body.Replace("{Datetime}", bookingDate + " " + getBooking.FromTime + " to " + getBooking.ToTime);

                    mail.SendGeneralMail("Therapist Booking Confirmation", getUserTherapistEmail.Email, body);

                    //For Patient
                    string body1 = mail.createEmailBody("PatientBookingConfirmation.html");
                    body1 = body1.Replace("{PatientName}", getUserPatient.FirstName + " " + getUserPatient.LastName);
                    body1 = body1.Replace("{UserName}", getUserPatient.FirstName + " " + getUserPatient.LastName);
                    body1 = body1.Replace("{PatientServices}", getServiceName);
                    body1 = body1.Replace("{PatientAddress}", getBooking.Address);
                    body1 = body1.Replace("{TherapistName}", getUserTherapist.FirstName + " " + getUserTherapist.LastName);
                    body1 = body1.Replace("{Datetime}", bookingDate + " " + getBooking.FromTime + " to " + getBooking.ToTime);

                    mail.SendGeneralMail("Patient Booking Confirmation", getUserPatientEmail.Email, body1);
                }


                return(Ok(model));
            }
            catch (Exception ex)
            {
                responseData.message = ex.Message != null?ex.Message.ToString() : "server error";

                return(Ok(responseData));
            }
        }