public string InsertUser(User pUser)
        {
            string result = string.Empty;
            User   _user  = null;


            if (pUser != null)
            {
                pUser.UserId = pUser.UserId.ToLower();
                _user        = (from p in context.User
                                where p.UserId == pUser.UserId
                                select p).FirstOrDefault();
                if (_user == null)
                {
                    _user = (from p in context.User
                             where p.UserId == pUser.UserId.ToUpper()
                             select p).FirstOrDefault();
                }
                if (_user == null)
                {
                    if (!string.IsNullOrEmpty(pUser.Password) && (pUser.Type == ConstantsVar.Patient || pUser.Type == ConstantsVar.Therapist || pUser.Type == ConstantsVar.Support))
                    {
                        AddUser luser = new AddUser();
                        luser.secretkey = ConfigVars.NewInstance.secretkey;
                        luser.username  = pUser.UserId;
                        luser.fn        = pUser.Name;
                        luser.ln        = pUser.Name;
                        luser.password  = pUser.Password;

                        VSeeHelper lhelper = new VSeeHelper();
                        var        resUser = lhelper.AddUser(luser);
                        if (resUser != null && resUser["status"] == "success")
                        {
                            pUser.Vseeid = "onedirect+" + pUser.UserId.ToLower();
                            context.User.Add(pUser);
                            context.SaveChanges();
                            result = "success";
                        }
                    }
                    else
                    {
                        context.User.Add(pUser);
                        context.SaveChanges();
                        result = "success";
                    }
                    //Prabhu
                }
                else
                {
                    result = "Username already exists";
                }
            }

            return(result);
        }
        public string UpdateUser(User pUser)
        {
            string result = string.Empty;
            var    _user  = (from p in context.User
                             where p.UserId == pUser.UserId
                             select p).FirstOrDefault();

            if (_user != null)
            {
                dynamic    resUser = null;
                VSeeHelper lhelper = new VSeeHelper();

                AddUser luser = new AddUser();
                luser.secretkey = ConfigVars.NewInstance.secretkey;
                luser.username  = pUser.UserId;
                luser.fn        = pUser.Name;
                luser.ln        = pUser.Name;
                luser.password  = pUser.Password;


                if (!string.IsNullOrEmpty(pUser.Password) && !string.IsNullOrEmpty(pUser.Vseeid) && (pUser.Type == ConstantsVar.Patient || pUser.Type == ConstantsVar.Therapist || pUser.Type == ConstantsVar.Support))
                {
                    resUser = lhelper.UpdateUser(luser);
                }
                else if (!string.IsNullOrEmpty(pUser.Password) && string.IsNullOrEmpty(pUser.Vseeid) && (pUser.Type == ConstantsVar.Patient || pUser.Type == ConstantsVar.Therapist || pUser.Type == ConstantsVar.Support))
                {
                    resUser = lhelper.AddUser(luser);
                }

                if (resUser != null && resUser["status"] == "success")
                {
                    _user.Vseeid = "onedirect+" + pUser.UserId.ToLower();
                }

                _user.Name            = pUser.Name;
                _user.Email           = pUser.Email;
                _user.Address         = pUser.Address;
                _user.Phone           = pUser.Phone;
                _user.Password        = pUser.Password;
                _user.Type            = pUser.Type;
                _user.Npi             = pUser.Npi;
                _user.EncryptPasswrod = pUser.EncryptPasswrod;

                context.Entry(_user).State = EntityState.Modified;
                context.SaveChanges();
                result = "success";
            }

            return(result);
        }
        //delete the provider record not having any patients assigned
        public IActionResult DeleteProvider(string provider)
        {
            try
            {
                var _user = (from p in context.User where p.UserId == provider select p).FirstOrDefault();

                context.User.Remove(_user);


                int res = context.SaveChanges();
                if (res > 0)
                {
                    VSeeHelper lhelper = new VSeeHelper();
                    DeleteUser luser   = new DeleteUser();
                    luser.secretkey = ConfigVars.NewInstance.secretkey;
                    luser.username  = _user.UserId;
                    var resUser = lhelper.DeleteUser(luser);
                    if (resUser != null && resUser["status"] == "success")
                    {
                        //Insert to User Activity Log
                        UserActivityLog llog = new UserActivityLog();
                        llog.SessionId        = HttpContext.Session.GetString("SessionId");
                        llog.ActivityType     = "Update";
                        llog.StartTimeStamp   = !string.IsNullOrEmpty(HttpContext.Session.GetString("SessionTime")) ? Convert.ToDateTime(HttpContext.Session.GetString("SessionTime")) : DateTime.Now;
                        llog.Duration         = Convert.ToInt32((DateTime.Now - Convert.ToDateTime(HttpContext.Session.GetString("SessionTime"))).TotalSeconds);
                        llog.RecordChangeType = "Delete";
                        llog.RecordType       = "Provider";
                        llog.Comment          = "Record deleted";
                        llog.RecordJson       = JsonConvert.SerializeObject(_user);
                        llog.UserId           = HttpContext.Session.GetString("UserId");
                        llog.UserName         = HttpContext.Session.GetString("UserName");
                        llog.UserType         = HttpContext.Session.GetString("UserType");
                        if (!string.IsNullOrEmpty(HttpContext.Session.GetString("ReviewID")))
                        {
                            llog.ReviewId = HttpContext.Session.GetString("ReviewID");
                        }
                        lIUserActivityLogRepository.InsertUserActivityLog(llog);
                    }
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Provider"));
            }
            return(RedirectToAction("Index", "Provider"));
        }
 public JsonResult generateuri(string id = "")
 {
     try
     {
         if (!string.IsNullOrEmpty(id))
         {
             AppointmentSchedule lappointment = lIAppointmentScheduleRepository.GetAppointment(id);
             if (lappointment != null && lappointment.PatientId.HasValue)
             {
                 Patient lpatient = IPatient.GetPatientByPatientID(lappointment.PatientId.Value);
                 if (lpatient != null)
                 {
                     User pPatient            = lIUserRepository.getUser(lpatient.PatientLoginId);
                     User pTherapistorSupport = lIUserRepository.getUser(lappointment.UserId);
                     if (pPatient != null && !string.IsNullOrEmpty(pPatient.Vseeid) && pTherapistorSupport != null && !string.IsNullOrEmpty(pTherapistorSupport.Vseeid))
                     {
                         VSeeHelper vsee   = new VSeeHelper();
                         dynamic    resURI = vsee.GetURI(pTherapistorSupport.Vseeid, pTherapistorSupport.Password, pPatient.Vseeid);
                         if (resURI != null)
                         {
                             lappointment.VseeUrl = resURI;
                             int _result = lIAppointmentScheduleRepository.UpdateAppointment(lappointment);
                             if (_result > 0)
                             {
                                 return(Json(new { result = "success", url = resURI }));
                             }
                             else
                             {
                                 return(Json(""));
                             }
                         }
                         else
                         {
                             return(Json(""));
                         }
                     }
                     else
                     {
                         return(Json(""));
                     }
                 }
                 else
                 {
                     return(Json(""));
                 }
             }
             else
             {
                 return(Json(""));
             }
         }
         else
         {
             return(Json(""));
         }
     }
     catch (Exception ex)
     {
         return(Json(""));
     }
 }
        public JsonResult updateappointment(string appointmentid)
        {
            string timezoneid = TimeZoneInfo.Local.SupportsDaylightSavingTime ? TimeZoneInfo.Local.DaylightName : TimeZoneInfo.Local.StandardName;//"US Eastern Standard Time";//

            try
            {
                if (!string.IsNullOrEmpty(appointmentid))
                {
                    AppointmentSchedule lappointment = lIAppointmentScheduleRepository.GetAppointment(appointmentid);
                    if (lappointment != null && lappointment.PatientId.HasValue)
                    {
                        Patient lpatient = IPatient.GetPatientByPatientID(lappointment.PatientId.Value);
                        if (lpatient != null)
                        {
                            User pPatient            = lIUserRepository.getUser(lpatient.PatientLoginId);
                            User pTherapistorSupport = lIUserRepository.getUser(lappointment.UserId);
                            if (pPatient != null && !string.IsNullOrEmpty(pPatient.Vseeid) && pTherapistorSupport != null && !string.IsNullOrEmpty(pTherapistorSupport.Vseeid))
                            {
                                VSeeHelper vsee   = new VSeeHelper();
                                dynamic    resURI = vsee.GetURI(pTherapistorSupport.Vseeid, pTherapistorSupport.Password, pPatient.Vseeid);
                                if (resURI != null)
                                {
                                    lappointment.VseeUrl = resURI;
                                    int _result = lIAppointmentScheduleRepository.UpdateAppointment(lappointment);
                                    if (_result > 0)
                                    {
                                        return(Json(new { Status = (int)HttpStatusCode.OK, result = "success", url = resURI, TimeZone = timezoneid }));
                                    }
                                    else
                                    {
                                        return(Json(new { Status = (int)HttpStatusCode.Created, result = "not updated", TimeZone = timezoneid }));
                                    }
                                }
                                else
                                {
                                    return(Json(new { Status = (int)HttpStatusCode.Created, result = "not updated", TimeZone = timezoneid }));
                                }
                            }
                            else
                            {
                                return(Json(new { Status = (int)HttpStatusCode.Created, result = "not updated", TimeZone = timezoneid }));
                            }
                        }
                        else
                        {
                            return(Json(new { Status = (int)HttpStatusCode.BadRequest, result = "patient is not registered", TimeZone = timezoneid }));
                        }
                    }
                    else
                    {
                        return(Json(new { Status = (int)HttpStatusCode.BadRequest, result = "appointment is not registered", TimeZone = timezoneid }));
                    }
                }
                else
                {
                    return(Json(new { Status = (int)HttpStatusCode.Created, result = "request string is not proper", TimeZone = timezoneid }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Status = (int)HttpStatusCode.InternalServerError, result = "Internal server error", TimeZone = timezoneid }));
            }
        }
        public JsonResult bookappointment([FromBody] bookappointment pbookappointment, string sessionid)
        {
            string timezoneid = TimeZoneInfo.Local.SupportsDaylightSavingTime ? TimeZoneInfo.Local.DaylightName : TimeZoneInfo.Local.StandardName;//"US Eastern Standard Time";//

            try
            {
                if (!string.IsNullOrEmpty(sessionid) && pbookappointment != null && !string.IsNullOrEmpty(pbookappointment.UserID) && !string.IsNullOrEmpty(pbookappointment.DateTime))
                {
                    Patient lpatient = IPatient.GetPatientBySessionID(sessionid);
                    if (lpatient != null)
                    {
                        User luser = lIUserRepository.getUser(pbookappointment.UserID);
                        if (luser != null)
                        {
                            AppointmentSchedule lbookAppointment = lIAppointmentScheduleRepository.CheckAppointmentSchedule(pbookappointment.UserID, Utilities.getUserType(luser.Type.ToString()), Convert.ToDateTime(pbookappointment.DateTime));
                            if (lbookAppointment == null)
                            {
                                lbookAppointment = new AppointmentSchedule();

                                lbookAppointment.UserType     = luser.Type == 1 ? "Support" : "Therapist";
                                lbookAppointment.UserId       = luser.UserId;
                                lbookAppointment.Datetime     = Convert.ToDateTime(pbookappointment.DateTime);
                                lbookAppointment.PatientId    = lpatient.PatientId;
                                lbookAppointment.SlotStatus   = "Booked";
                                lbookAppointment.CallStatus   = "Open";
                                lbookAppointment.CreateDate   = DateTime.UtcNow;
                                lbookAppointment.UpdateDate   = DateTime.UtcNow;
                                lbookAppointment.RecordedFile = "";
                            }
                            else if (lbookAppointment != null && lbookAppointment.CallStatus == "Extra")
                            {
                                lbookAppointment.Datetime   = Convert.ToDateTime(pbookappointment.DateTime);
                                lbookAppointment.PatientId  = lpatient.PatientId;
                                lbookAppointment.SlotStatus = "Booked";
                                lbookAppointment.CallStatus = "Open";
                                lbookAppointment.UpdateDate = DateTime.UtcNow;
                            }

                            User pPatient            = lIUserRepository.getUser(lpatient.PatientLoginId);
                            User pTherapistorSupport = lIUserRepository.getUser(luser.UserId);
                            if (pPatient != null && !string.IsNullOrEmpty(pPatient.Vseeid) && pTherapistorSupport != null && !string.IsNullOrEmpty(pTherapistorSupport.Vseeid))
                            {
                                VSeeHelper vsee   = new VSeeHelper();
                                dynamic    resURI = vsee.GetURI(pTherapistorSupport.Vseeid, pTherapistorSupport.Password, pPatient.Vseeid);
                                if (resURI != null)
                                {
                                    lbookAppointment.VseeUrl = resURI;
                                    int _result = 0;
                                    if (!string.IsNullOrEmpty(lbookAppointment.AppointmentId))
                                    {
                                        _result = lIAppointmentScheduleRepository.UpdateAppointment(lbookAppointment);
                                    }
                                    else
                                    {
                                        lbookAppointment.AppointmentId = Guid.NewGuid().ToString();
                                        _result = lIAppointmentScheduleRepository.InsertAppointment(lbookAppointment);
                                    }
                                    if (_result > 0)
                                    {
                                        string content = "New appointment has booked.<br><a href='" + ConfigVars.NewInstance.url + "?ruserid=" + Utilities.EncryptText(pTherapistorSupport.UserId) + "&rtype=" + Utilities.EncryptText(pTherapistorSupport.Type.ToString()) + "&rpage=" + Utilities.EncryptText("appointment") + "'> Click to view</a>";
                                        Smtp.SendGridEmail(luser.Email, "Appointment", content);
                                        return(Json(new { Status = (int)HttpStatusCode.OK, result = "success", TimeZone = timezoneid }));
                                    }
                                    else
                                    {
                                        return(Json(new { Status = (int)HttpStatusCode.Created, result = "not inserted", TimeZone = timezoneid }));
                                    }
                                }
                                else
                                {
                                    return(Json(new { Status = (int)HttpStatusCode.Created, result = "not inserted", TimeZone = timezoneid }));
                                }
                            }
                            else
                            {
                                return(Json(new { Status = (int)HttpStatusCode.Created, result = "not inserted", TimeZone = timezoneid }));
                            }
                        }
                        else
                        {
                            return(Json(new { Status = (int)HttpStatusCode.BadRequest, result = "user record is not found", TimeZone = timezoneid }));
                        }
                    }
                    else
                    {
                        return(Json(new { Status = (int)HttpStatusCode.BadRequest, result = "patient is not registered", TimeZone = timezoneid }));
                    }
                }
                else
                {
                    return(Json(new { Status = (int)HttpStatusCode.Created, result = "request string is not proper", TimeZone = timezoneid }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Status = (int)HttpStatusCode.InternalServerError, result = "Internal server error", TimeZone = timezoneid }));
            }
        }