Exemplo n.º 1
0
        public IHttpActionResult SaveBooking(BookingModel 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;

                if (RefType == "1")
                {
                    model.TherapistID = Convert.ToInt32(RefID);
                }
                else if (RefType == "2")
                {
                    model.PatientID = Convert.ToInt32(RefID);
                }

                BookingDL obj = new BookingDL();
                obj.SaveBooking(model, UserId);

                //if (model.BookingID == 0)
                //{
                //    SendMail mail = new SendMail();
                //    RegisterDL obj1 = new RegisterDL();
                //    var list = obj1.GetUserDetails(Convert.ToInt32(UserId), Convert.ToInt32(RefType));

                //    var getAllService = obj1.GetAllServices();
                //    string getServiceName = "";
                //    foreach (var item in model.BookingSerList)
                //    {
                //        getServiceName += getAllService.Where(x => x.ServiceID == item.ServiceID).FirstOrDefault().ServiceName + ",";
                //    }
                //    getServiceName = getServiceName.TrimEnd(',');

                //    string body = mail.createEmailBody("PatientBooking.html");
                //    body = body.Replace("{UserName}", list[0].FirstName + " " + list[0].LastName);
                //    body = body.Replace("{servicename}", getServiceName);

                //    mail.SendGeneralMail("Patient Booking", list[0].Email, body);
                //}

                int bookId = Convert.ToInt32(RefID);

                int BookingID = entities.Bookings.Where(x => x.PatientID == bookId).Select(x => x.BookingID).FirstOrDefault();


                responseData.message = "Booking details saved successfully";
                responseData.success = true;
                responseData.data    = BookingID;
                return(Ok(responseData));
            }
            catch (Exception ex)
            {
                responseData.message = ex.Message != null?ex.Message.ToString() : "server error";

                responseData.success = false;
                return(Ok(responseData));
            }
        }