public ActionResult GetAllCourses() { try { IRepositery _repo = new Repositery(); IList <Abeced_Data.Abeced.Data.Course> AllCourses = _repo.GetAllCourses(); List <CourseModel> CourseList = AllCourses.Select(x => new CourseModel { CourseId = x.CourseId, name = x.name, description = x.description, img = x.img, duration = x.duration, dateCreated = x.dateCreated, numFacts = x.numFacts, points = x.points, creatorName = x.creatorName, subCatID = x.subCatID, subCatName = x.subCatName, mainCatName = x.mainCatName, userID = x.userID, averageRating = x.averageRating }).ToList(); return(View(CourseList)); } catch (Exception) { throw; } }
public ActionResult AddorEditMainCategory(MainCategory mainCategory) { try { if (mainCategory.imgFile != null) { string filename = Path.GetFileNameWithoutExtension(mainCategory.imgFile.FileName); string extension = Path.GetExtension(mainCategory.imgFile.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; string fileRelativePath = "~/App_Files/Images/" + filename; Uri baseuri = new Uri(Request.Url.ToString()); Uri fileFullPath = new Uri(baseuri, VirtualPathUtility.ToAbsolute(fileRelativePath)); fileFullPath.ToString().Trim('{'); fileFullPath.ToString().Trim('}'); mainCategory.img = fileFullPath.ToString(); mainCategory.imgFile.SaveAs(Path.Combine(Server.MapPath("~/App_Files/Images/"), filename)); } Abeced_Data.Abeced.Data.MainCategory MainCats = new Abeced_Data.Abeced.Data.MainCategory { name = mainCategory.name, description = mainCategory.description, img = mainCategory.img, }; Repositery _repo = new Repositery(); _repo.SaveMainCategory(MainCats); return(Json(new { returnmsg = "Success" }, JsonRequestBehavior.AllowGet)); } catch (Exception) { throw; } }
public ActionResult AddorEditCard(int i = 0) { FactModel fact = new FactModel(); //IEnumerable<CourseModel> courseList; //try //{ // HttpResponseMessage response = DataAccess.WebClient.GetAsync("Courses").Result; // courseList = response.Content.ReadAsAsync<IEnumerable<CourseModel>>().Result.ToList(); // fact.CourseList = courseList.ToList(); // return View(fact); //} //catch (Exception ex) //{ // Console.Write(ex.Message); // return View(); //} Repositery _repo = new Repositery(); IList <Abeced_Data.Abeced.Data.Course> course = _repo.GetAllCourses(); List <CourseModel> list = course.Select(x => new CourseModel { CourseId = x.CourseId, name = x.name }).ToList(); fact.CourseList = list; return(View(fact)); }
// GET: FlashCard public ActionResult SelectCards() { //try //{ IEnumerable<FactModelRetrieve> factModelList = null; // var response = DataAccess.WebClient.GetAsync("flashcards/cards/" + TempData["CourseId"]); // response.Wait(); // var result = response.Result; // if (result.IsSuccessStatusCode) // { // var readTask = result.Content.ReadAsAsync<List<FactModelRetrieve>>(); // readTask.Wait(); // factModelList = readTask.Result; // } // else // { // factModelList = Enumerable.Empty<FactModelRetrieve>(); // ModelState.AddModelError(string.Empty, "Server Error"); // } // TempData["SelectedCards"] = factModelList; // TempData.Keep(); // //ViewBag.Facts = factModelList; // return Json(new {data = factModelList},JsonRequestBehavior.AllowGet); //} //catch (Exception) //{ // throw; //} try { Repositery _repo = new Repositery(); List <Abeced_Data.Abeced.Data.Fact> FactsList = _repo.getCourseFacts(Convert.ToInt32(TempData["CourseId"])); List <FactModelRetrieve> factModelList = FactsList.Select(x => new FactModelRetrieve { FactId = x.FactId, question = x.question, answer = x.answer, factsheet = x.factsheet }).ToList(); TempData["SelectedCards"] = factModelList; TempData.Keep(); return(Json(new { data = factModelList }, JsonRequestBehavior.AllowGet)); } catch (Exception) { throw; } }
//int CourseId; public ActionResult SelectCardIndex(string CourseID, string CourseName) { ViewBag.CourseName = CourseName; //ViewData["CouseName"] = CourseName; TempData["CourseId"] = Int32.Parse(CourseID); TempData.Keep(); Sharing shares = new Sharing(); Repositery _repo = new Repositery(); List <Abeced_Data.Abeced.Data.AspNetUser> AllUsers = _repo.getAllAbecedUsers(); List <RegisterViewModel> users = AllUsers.Select(x => new RegisterViewModel { UserId = x.Id, UserName = x.UserName, Email = x.Email, Fname = x.Fname, Lname = x.Lname }).ToList(); shares.User = users; //IEnumerable<RegisterViewModel> AllUsersList = null; //var response = DataAccess.WebClient.GetAsync("User"); //response.Wait(); //var result = response.Result; //if (result.IsSuccessStatusCode) //{ // var readTask = result.Content.ReadAsAsync<List<RegisterViewModel>>(); // readTask.Wait(); // AllUsersList = readTask.Result; // shares.User = AllUsersList.ToList(); //} //else //{ // AllUsersList = Enumerable.Empty<RegisterViewModel>(); // ModelState.AddModelError(string.Empty, "Server Error"); //} return(View(shares)); }
public ActionResult FactsToMatch(string SelectedCards) { //factIds variable to be consistent with the parameter in the web apis string factIds = SelectedCards; //IEnumerable<FactModelRetrieve> selectedFactsList = null; //var response = DataAccess.WebClient.GetAsync("flashcards/selectedCards/"+ factIds); //response.Wait(); //var result = response.Result; //if (result.IsSuccessStatusCode) //{ // var readTask = result.Content.ReadAsAsync<List<FactModelRetrieve>>(); // readTask.Wait(); // selectedFactsList = readTask.Result; //} //else //{ // selectedFactsList = Enumerable.Empty<FactModelRetrieve>(); // ModelState.AddModelError(string.Empty, "Server Error"); //} Repositery _repo = new Repositery(); List <Abeced_Data.Abeced.Data.Fact> getFacts = _repo.GetSelectedFacts(factIds); // mapping the factlist with the facts model List <FactModelRetrieve> selectedFactsList = getFacts.Select(x => new FactModelRetrieve { FactId = x.FactId, question = x.question, answer = x.answer, factsheet = x.factsheet, qAudio = x.qAudio, aAudio = x.aAudio, fsAudio = x.fsAudio, qImage = x.qImage, aImage = x.aImage, }).ToList(); return(View(selectedFactsList)); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { Repositery _repo = new Repositery(); if (!ModelState.IsValid) { return(View(model)); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); if (result == SignInStatus.Success) { FormsAuthentication.SetAuthCookie(model.Email, model.RememberMe); AspNetUser Person = _repo.getPerson(model.Email); Session["UserId"] = Person.Id; Session["Email"] = Person.Email; Session["UserName"] = Person.UserName; return(RedirectToAction("Dashboard", "FlashCard")); } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "Network Error Please try again"); return(View(model)); //switch (result) //{ // case SignInStatus.Success: // return RedirectToLocal(returnUrl); // case SignInStatus.LockedOut: // return View("Lockout"); // case SignInStatus.RequiresVerification: // return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }); // case SignInStatus.Failure: // default: // ModelState.AddModelError("", "Invalid login attempt."); // return View(model); //} }
public ActionResult ShareCards(Sharing sharing) // this objected is posted from the view and consist of user selected for sharing { //if (Session["SelectedCardsString"] != null) //{ // sharing.SenderId = 2; // sharing.SharedWithIds = string.Join(",", sharing.SelectedIds); // sharing.FactList = Session["SelectedCardsString"].ToString(); // HttpResponseMessage response = DataAccess.WebClient.PostAsJsonAsync("Sharings", sharing).Result; // if (response.IsSuccessStatusCode) // { // Console.Write("Shared"); // } // else // { // Console.Write("Not shared"); // } //} //else //{ // ViewBag.Success = "Select Cards First"; //} if (Session["SelectedCardsString"] != null) { Abeced_Data.Abeced.Data.Sharing cardsShared = new Abeced_Data.Abeced.Data.Sharing { AbecedUserId_Sharer = "ed08da0c-f25f-4da1-b2e3-ba39e5cd1246", SharedWithIds = string.Join(",", sharing.SelectedIds), FactList = Session["SelectedCardsString"].ToString() }; Repositery _repo = new Repositery(); _repo.SaveSharing(cardsShared); return(Json(new { returnmsg = "Success" }, JsonRequestBehavior.AllowGet)); } return(Json(new { returnmsg = "failure" }, JsonRequestBehavior.AllowGet)); }
public ActionResult QuizesJSONData() { string factIds = TempData["SelectedFactsToMatchIds"] as string; //IEnumerable<FactModelRetrieve> selectedFactsList = null; //var response = DataAccess.WebClient.GetAsync("flashcards/selectedCards/" + factIds); //response.Wait(); //var result = response.Result; //if (result.IsSuccessStatusCode) //{ // var readTask = result.Content.ReadAsAsync<List<FactModelRetrieve>>(); // readTask.Wait(); // selectedFactsList = readTask.Result; //} //else //{ // selectedFactsList = Enumerable.Empty<FactModelRetrieve>(); // ModelState.AddModelError(string.Empty, "Server Error"); //} Repositery _repo = new Repositery(); List <Abeced_Data.Abeced.Data.Fact> getFacts = _repo.GetSelectedFacts(factIds); // mapping the factlist with the facts model List <FactModelRetrieve> selectedFactsList = getFacts.Select(x => new FactModelRetrieve { FactId = x.FactId, question = x.question, answer = x.answer, factsheet = x.factsheet, qAudio = x.qAudio, aAudio = x.aAudio, fsAudio = x.fsAudio, qImage = x.qImage, aImage = x.aImage, }).ToList(); return(Json(new { factList = selectedFactsList }, JsonRequestBehavior.AllowGet)); }
public ActionResult AddorEditSubCategory(int id = 0) { //SubCategory subCategory = new SubCategory(); //IEnumerable<MainCategoryList> mainCategoryList; //try //{ // HttpResponseMessage response = DataAccess.WebClient.GetAsync("MainCategories").Result; // mainCategoryList = response.Content.ReadAsAsync<IEnumerable<MainCategoryList>>().Result.ToList(); // subCategory.MainCat = mainCategoryList.ToList(); // ViewBag.MainCatList = subCategory.MainCat; // return View(subCategory); //} //catch (Exception ex) //{ // Console.Write(ex.Message); // return View(); //} try { SubCategory Subcats = new SubCategory(); Repositery _repo = new Repositery(); IList <Abeced_Data.Abeced.Data.MainCategory> mainCats = _repo.GetAllMainCategories(); List <MainCategoryList> list = mainCats.Select(x => new MainCategoryList { MainCategoryId = x.MainCategoryId, name = x.name }).ToList(); Subcats.MainCat = list; return(View(Subcats)); } catch (Exception) { throw; } }
public ActionResult AddorEditCourse(CourseModel course) { try { if (course.imgFile != null) { string filename = Path.GetFileNameWithoutExtension(course.imgFile.FileName); string extension = Path.GetExtension(course.imgFile.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; string fileRelativePath = "~/App_Files/Images/" + filename; Uri baseuri = new Uri(Request.Url.ToString()); Uri fileFullPath = new Uri(baseuri, VirtualPathUtility.ToAbsolute(fileRelativePath)); fileFullPath.ToString().Trim('{'); fileFullPath.ToString().Trim('}'); course.img = fileFullPath.ToString(); course.imgFile.SaveAs(Path.Combine(Server.MapPath("~/App_Files/Images/"), filename)); } Abeced_Data.Abeced.Data.Course cor = new Abeced_Data.Abeced.Data.Course { name = course.name, description = course.description, img = course.img, duration = course.duration, dateCreated = DateTime.Now, numFacts = course.numFacts, SubjectIds = course.SubjectIds, AbecedUserId = "ed08da0c-f25f-4da1-b2e3-ba39e5cd1246" // Session["UserId"].ToString() }; Repositery _repo = new Repositery(); _repo.SaveCourse(cor); return(Json(new { returnmsg = "Success" }, JsonRequestBehavior.AllowGet)); } catch (Exception) { throw; } }
public ActionResult ShareCards() { Sharing shares = new Sharing(); //IEnumerable<RegisterViewModel> AllUsersList = null; //var response = DataAccess.WebClient.GetAsync("User"); //response.Wait(); //var result = response.Result; //if (result.IsSuccessStatusCode) //{ // var readTask = result.Content.ReadAsAsync<List<RegisterViewModel>>(); // readTask.Wait(); // AllUsersList = readTask.Result; // shares.User = AllUsersList.ToList(); //} //else //{ // AllUsersList = Enumerable.Empty<RegisterViewModel>(); // ModelState.AddModelError(string.Empty, "Server Error"); //} Repositery _repo = new Repositery(); List <Abeced_Data.Abeced.Data.AspNetUser> AllUsers = _repo.getAllAbecedUsers(); List <RegisterViewModel> users = AllUsers.Select(x => new RegisterViewModel { UserId = x.Id, UserName = x.UserName, Email = x.Email, Fname = x.Fname, Lname = x.Lname }).ToList(); shares.User = users; return(PartialView(shares)); }
public ActionResult AddorEditCourse(int id = 0) { try { CourseModel course = new CourseModel(); Repositery _repo = new Repositery(); IList <Abeced_Data.Abeced.Data.Subject> subject = _repo.getSubjects(); List <SubjectModel> list = subject.Select(x => new SubjectModel { SubjectId = x.SubjectId, SubjectName = x.SubjectName }).ToList(); course.SubjectList = list; return(View(course)); } catch (Exception) { throw; } }
public ActionResult AddorEditCard(FactModel fact) { try { Repositery _repo = new Repositery(); if (fact.aImage != null) { string filename = Path.GetFileNameWithoutExtension(fact.aImage.FileName); string extension = Path.GetExtension(fact.aImage.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; string fileRelativePath = "~/App_Files/Images/" + filename; Uri baseuri = new Uri(Request.Url.ToString()); Uri fileFullPath = new Uri(baseuri, VirtualPathUtility.ToAbsolute(fileRelativePath)); fileFullPath.ToString().Trim('{'); fileFullPath.ToString().Trim('}'); fact.aImagePath = fileFullPath.ToString(); fact.aImage.SaveAs(Path.Combine(Server.MapPath("~/App_Files/Images/"), filename)); } else { fact.aImagePath = null; } if (fact.qImage != null) { string filename = Path.GetFileNameWithoutExtension(fact.qImage.FileName); string extension = Path.GetExtension(fact.qImage.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; string fileRelativePath = "~/App_Files/Images/" + filename; Uri baseuri = new Uri(Request.Url.ToString()); Uri fileFullPath = new Uri(baseuri, VirtualPathUtility.ToAbsolute(fileRelativePath)); fileFullPath.ToString().Trim('{'); fileFullPath.ToString().Trim('}'); fact.qImagePath = fileFullPath.ToString(); fact.qImage.SaveAs(Path.Combine(Server.MapPath("~/App_Files/Images/"), filename)); } else { fact.qImagePath = null; } if (fact.qAudio != null) { string filename = Path.GetFileNameWithoutExtension(fact.qAudio.FileName); string extension = Path.GetExtension(fact.qAudio.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; string fileRelativePath = "~/App_Files/audios/" + filename; Uri baseuri = new Uri(Request.Url.ToString()); Uri fileFullPath = new Uri(baseuri, VirtualPathUtility.ToAbsolute(fileRelativePath)); fileFullPath.ToString().Trim('{'); fileFullPath.ToString().Trim('}'); fact.qAudioPath = fileFullPath.ToString(); fact.qAudio.SaveAs(Path.Combine(Server.MapPath("~/App_Files/audios/"), filename)); } else { fact.qAudioPath = null; } if (fact.aAudio != null) { string filename = Path.GetFileNameWithoutExtension(fact.aAudio.FileName); string extension = Path.GetExtension(fact.aAudio.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; string fileRelativePath = "~/App_Files/audios/" + filename; Uri baseuri = new Uri(Request.Url.ToString()); Uri fileFullPath = new Uri(baseuri, VirtualPathUtility.ToAbsolute(fileRelativePath)); fileFullPath.ToString().Trim('{'); fileFullPath.ToString().Trim('}'); fact.aAudioPath = fileFullPath.ToString(); fact.aAudio.SaveAs(Path.Combine(Server.MapPath("~/App_Files/audios/"), filename)); } else { fact.aAudioPath = null; } if (fact.fsAudio != null) { string filename = Path.GetFileNameWithoutExtension(fact.fsAudio.FileName); string extension = Path.GetExtension(fact.fsAudio.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; string fileRelativePath = "~/App_Files/audios/" + filename; Uri baseuri = new Uri(Request.Url.ToString()); Uri fileFullPath = new Uri(baseuri, VirtualPathUtility.ToAbsolute(fileRelativePath)); fileFullPath.ToString().Trim('{'); fileFullPath.ToString().Trim('}'); fact.fsAudioPath = fileFullPath.ToString(); fact.fsAudio.SaveAs(Path.Combine(Server.MapPath("~/App_Files/audios/"), filename)); } else { fact.fsAudioPath = null; } Abeced_Data.Abeced.Data.Fact myfact = new Abeced_Data.Abeced.Data.Fact { courseID = fact.courseID, question = fact.question, qImage = fact.qImagePath, qAudio = fact.qAudioPath, answer = fact.answer, aImage = fact.aImagePath, aAudio = fact.aAudioPath, factsheet = fact.factsheet, fsAudio = fact.fsAudioPath, userID = 1 }; _repo.SaveFact(myfact); return(Json(new { returnmsg = "Success" }, JsonRequestBehavior.AllowGet)); } catch (Exception) { throw; } }