public ActionResult AddCourse(tblCourse objCourse, HttpPostedFileBase file) { try { if (ModelState.IsValid) { int rows = 0; TblUser sessionUser = (TblUser)Session["UserSession"]; objCourse.createdBy = sessionUser.UserId; objCourse.tenantId = sessionUser.TenantId; newException.AddDummyException(":- " + objCourse.tenantId); objCourse.ZipFile = file; if (objCourse.ContentModuleId > 0) { rows = cc.EditCourse(objCourse); } else { rows = cc.AddCourse(objCourse); } if (rows != 0) { TempData["CourseMessage"] = "Course Saved Successfully"; return(View("AddNewCourse", objCourse)); //return RedirectToAction("Index"); } else { return(View("AddNewCourse", objCourse)); } } return(View("AddNewCourse", objCourse)); } catch (Exception ex) { newException.AddException(ex); return(View("AddNewCourse")); } }
public string GetEnquiry(string emailContent) { try { JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; object[] objTblQue = (object[])json_serializer.DeserializeObject(emailContent); foreach (Dictionary <string, object> item in objTblQue) { //var emailBody = objTblQue.Message; var emailSubject = "New Enquiry "; tblEmails objEmail = new tblEmails(); var emailBody = ""; emailBody += "<p></p>Name :- " + Convert.ToString(item["Name"]); emailBody += "<p></p>Email Id :- " + Convert.ToString(item["Email"]); emailBody += "<p></p>Contact No :- " + Convert.ToString(item["Contact"]); emailBody += "<p></p>Service Enquired About :- " + Convert.ToString(item["Service"]); emailBody += "<p></p>Message :- " + Convert.ToString(item["Message"]); objEmail.EmailTo = "*****@*****.**"; objEmail.EmailSubject = emailSubject; objEmail.EmailBody = emailBody; var emailResult = userRepository.InsertEmail(objEmail); return("Sent Successfully"); } } catch (Exception ex) { newException.AddDummyException(ex.ToString()); return("Failded"); } return("Failed"); }
public async Task <ActionResult> LaunchQuiz(int QuizId, string code) //public ActionResult LaunchQuiz(int QuizId, string code) { //newException.AddDummyException("Quiz ID First - " + Convert.ToString(QuizId)); bool isPlek = false; try { TblUser sessionUser = (TblUser)Session["UserSession"]; if (string.IsNullOrEmpty(code)) { QuizSession quizForSession = new QuizSession(); quizForSession.QuizId = Convert.ToInt32(QuizId); quizForSession.isUsed = false; lstQuiz.Add(quizForSession); Session["QuizId"] = lstQuiz; if (string.IsNullOrEmpty(Convert.ToString(Session["QuizId"]))) { newException.AddDummyException("Quiz Id in LaunchQuiz is Null"); } } List <TblQuiz> lstAllQuiz = new List <TblQuiz>(); if (sessionUser == null) { TenantRepository tr = new TenantRepository(); List <TblTenant> tenantDetails = new List <TblTenant>(); string host = Request.Url.Host; var tenantList1 = tr.VerifyTenantDomain(host); if (tenantList1.Count > 0) { if (tenantList1[0].TenantId == 6) { if (string.IsNullOrEmpty(code)) { return(Redirect("https://pumplace.plek.co/oidc/auth?client_id=1663f8ca-7b8a-42eb-ae3b-845e32be1baf&scope=openid&response_type=code&redirect_uri=https://quiz.rockettech.co.nz/")); } else { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Add("Access-Control-Allow-Origin", "*"); string tokenApi = "https://pumplace.plek.co/oidc/token"; var values = new Dictionary <string, string>(); values.Add("client_id", "1663f8ca-7b8a-42eb-ae3b-845e32be1baf"); values.Add("client_secret", "TZD4Jr837e6uymsJdyxH2jk8qxGQiK7gXDCmYqtC"); values.Add("grant_type", "authorization_code"); values.Add("code", code); values.Add("redirect_uri", "https://quiz.rockettech.co.nz/"); var content = new FormUrlEncodedContent(values); var responseTask = await client.PostAsync(tokenApi, content); var result = await responseTask.Content.ReadAsStringAsync(); var data = (JObject)JsonConvert.DeserializeObject(result); string token = data["access_token"].Value <string>();//Access Token Received //Now get User Details string userApi = "https://pumplace.plek.co/oidc/me"; client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); HttpResponseMessage response = await client.GetAsync(userApi); if (response.IsSuccessStatusCode) { string jsondata = await response.Content.ReadAsStringAsync(); var userData = (JObject)JsonConvert.DeserializeObject(jsondata); string email = userData["email"].Value <string>(); string name = userData["username"].Value <string>(); var userId = ur.IsUserExist(email, Request.Url.Host); if (userId == 0) { try { //Create user TblUser newUser = new TblUser(); newUser.FirstName = name; newUser.EmailId = email; newUser.RoleId = 3; newUser.IsActive = true; newUser.CreatedBy = 1; CommonFunctions common = new CommonFunctions(); newUser.Password = common.GetEncodePassword("123456"); var tenantList = tr.VerifyTenantDomain(Request.Url.Host); newUser.TenantId = tenantList[0].TenantId; var newUserId = ur.AddUser(newUser); if (newUserId > 0) { //Assign Quiz to Newly Created User //newException.AddDummyException("111 - " + Convert.ToString(QuizId)); var objQuiz = quizRepository.GetQuizByID(Convert.ToInt32(QuizId)); if (objQuiz != null) { if (objQuiz[0] != null) { if (objQuiz[0].TenantId == 6) { var assign = quizRepository.AssignQuiz(Convert.ToInt32(QuizId), newUserId, null); } } } userId = newUserId; } } catch (Exception ex) { newException.AddException(ex); } } else { //check Quiz assigned or not var isAssigned = quizRepository.CheckQuizAssignedUser(Convert.ToInt32(QuizId), userId); if (!isAssigned) { newException.AddDummyException("222 - " + QuizId); var objQuiz = quizRepository.GetQuizByID(Convert.ToInt32(QuizId)); if (objQuiz != null) { if (objQuiz[0] != null) { if (objQuiz[0].TenantId == 6) { var assign = quizRepository.AssignQuiz(Convert.ToInt32(QuizId), userId, null); } } } } } List <TblUser> tblUser = ur.GetUserById(userId); Session["UserSession"] = tblUser[0]; lstAllQuiz = quizRepository.GetQuizForLaunch(Convert.ToInt32(QuizId), userId); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; lstAllQuiz[0].hdnLaunchData = json_serializer.Serialize(lstAllQuiz[0]); isPlek = true; } } } } if (tenantList1[0].TenantId == 9) { //newException.AddDummyException("In - 111 "); CommonFunctions common = new CommonFunctions(); var password = common.GetEncodePassword("123456"); TblUser tblUser = ur.IsValidUser("*****@*****.**", password, Request.Url.Host); lstAllQuiz = quizRepository.GetQuizForLaunch(Convert.ToInt32(QuizId), tblUser.UserId); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; lstAllQuiz[0].hdnLaunchData = json_serializer.Serialize(lstAllQuiz[0]); //newException.AddDummyException("In - 222 "); isPlek = true; } } } else { if (sessionUser.TenantId == 6) { isPlek = true; //check Quiz assigned or not var isAssigned = quizRepository.CheckQuizAssignedUser(Convert.ToInt32(QuizId), sessionUser.UserId); //newException.AddDummyException(Convert.ToString(isAssigned)); if (!isAssigned) { //newException.AddDummyException("333 - " + QuizId); var objQuiz = quizRepository.GetQuizByID(Convert.ToInt32(QuizId)); if (objQuiz != null) { if (objQuiz[0] != null) { if (objQuiz[0].TenantId == 6) { var assign = quizRepository.AssignQuiz(Convert.ToInt32(QuizId), sessionUser.UserId, null); lstAllQuiz = quizRepository.GetQuizForLaunch(Convert.ToInt32(QuizId), sessionUser.UserId); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; lstAllQuiz[0].hdnLaunchData = json_serializer.Serialize(lstAllQuiz[0]); } } } } else { lstAllQuiz = quizRepository.GetQuizForLaunch(Convert.ToInt32(QuizId), sessionUser.UserId); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; lstAllQuiz[0].hdnLaunchData = json_serializer.Serialize(lstAllQuiz[0]); } } if (sessionUser.TenantId == 9) { //newException.AddDummyException("In - 111 "); CommonFunctions common = new CommonFunctions(); var password = common.GetEncodePassword("123456"); TblUser tblUser = ur.IsValidUser("*****@*****.**", password, Request.Url.Host); lstAllQuiz = quizRepository.GetQuizForLaunch(Convert.ToInt32(QuizId), tblUser.UserId); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; lstAllQuiz[0].hdnLaunchData = json_serializer.Serialize(lstAllQuiz[0]); //newException.AddDummyException("In - 222 "); isPlek = true; } else { lstAllQuiz = quizRepository.GetQuizForLaunch(Convert.ToInt32(QuizId), sessionUser.UserId); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; lstAllQuiz[0].hdnLaunchData = json_serializer.Serialize(lstAllQuiz[0]); } } if (isPlek) { return(View("LaunchQuizForPlek", lstAllQuiz[0])); } else { return(View("LaunchQuizNew", lstAllQuiz[0])); } } catch (Exception ex) { newException.AddException(ex); if (isPlek) { return(View("LaunchQuizForPlek")); } else { return(View("LaunchQuizNew")); } } }
// GET: Login public ActionResult Index(string code) { TblUser user = new TblUser(); List <TblTenant> tenantDetails = new List <TblTenant>(); try { string host = string.Empty; host = Request.Url.Host; var tenantList = tr.VerifyTenantDomain(host); if (tenantList.Count > 0) { if (tenantList[0].TenantId == 6) { if (!string.IsNullOrEmpty(code)) { if (!string.IsNullOrEmpty(Convert.ToString(Session["CourseId"]))) { return(RedirectToAction("LaunchCourse", "Assignment", new { @CourseId = Convert.ToInt32(Session["CourseId"]), @code = code })); } else { //newException.AddDummyException("in Quiz"); int quizId = 0; if (string.IsNullOrEmpty(Convert.ToString(Session["QuizId"]))) { newException.AddDummyException("Quiz Id is Null"); } var sessions = (List <QuizSession>)Session["QuizId"]; foreach (var item in sessions) { if (item.isUsed == false) { quizId = item.QuizId; item.isUsed = true; break; } } return(RedirectToAction("LaunchQuiz", "Assignment", new { @QuizId = quizId, @code = code })); } } } if (tenantList[0].TenantId > 0) { if (!string.IsNullOrEmpty(Convert.ToString(RouteData.Values["LogoutMessage"]))) { TempData["LogoutMessage"] = RouteData.Values["LogoutMessage"]; } user.TenantLogo = tenantList[0].Logo; Session["Logo"] = tenantList[0].Logo; TblUser userobj = checkcookie(); if (userobj != null) { user.EmailId = userobj.EmailId; user.Password = userobj.Password; } return(View("Login", user)); } else { return(View("NoClientAvailable")); } } else { return(View("NoClientAvailable")); } } catch (Exception ex) { newException.AddException(ex); return(View("Login", user)); } }