public JsonResult Index(QuestionOptionViewModel questionOption) { Question objQuestion = new Question(); objQuestion.QuestionName = questionOption.QuestionName; objQuestion.CategoryId = questionOption.CategoryId; objQuestion.IsActive = true; objQuestion.IsMultiple = false; objquizdbEntities.Questions.Add(objQuestion); objquizdbEntities.SaveChanges(); int questionId = objQuestion.QuestionId; foreach (var item in questionOption.ListOfOptions) { Option objOption = new Option(); objOption.OptionName = item; objOption.QuestionId = questionId; objquizdbEntities.Options.Add(objOption); objquizdbEntities.SaveChanges(); } Answer objAnswer = new Answer(); objAnswer.Answertext = questionOption.AnswerText; objAnswer.QuestionId = questionId; objquizdbEntities.Answers.Add(objAnswer); objquizdbEntities.SaveChanges(); return(Json(new { message = "data Successfilly added.", success = true }, JsonRequestBehavior.AllowGet)); }
public ActionResult AddMark([Bind(Include = "Total,Obtain,CourseId,StudentId")] Mark mark) { mark.Course = db.Courses.Find(mark.CourseId); mark.Student = db.Students.Where(x => x.UserName.Equals(mark.StudentId)).FirstOrDefault(); db.Marks.Add(mark); db.SaveChanges(); return(RedirectToAction("Result")); }
public ActionResult Create([Bind(Include = "CourseId,CourseName,Description,TeacherId")] Course course) { if (ModelState.IsValid) { db.Courses.Add(course); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(course)); }
public ActionResult AddUser(FormCollection fc) { var newuser = new ApplicationUser { UserName = fc["email"], Email = fc["email"] }; var result = userManager.Create(newuser, fc["password"]); if (result.Succeeded) { var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext())); userManager.AddToRole(newuser.Id, fc["ddl"]); if (fc["ddl"] == "Student") { using (MoodleDb db = new MoodleDb()) { Student s = new Student { Id = newuser.Id, UserName = newuser.UserName }; db.Students.Add(s); Directory.CreateDirectory(Path.Combine(Server.MapPath("~/UploadedFiles"), newuser.Id)); db.SaveChanges(); } } } else { TempData["msg"] = "An error occured while adding user"; } return(RedirectToAction("Index", "Admin")); }
public string DeleteUser(string id) { userManager.Delete(userManager.FindById(id)); MoodleDb db = new MoodleDb(); db.Students.Remove(db.Students.Find(id)); db.SaveChanges(); return("User deleted"); }
public ActionResult Upload(HttpPostedFileBase upload) { string id = User.Identity.GetUserId(); s = db.Students.Where(x => x.Id.Equals(id)).FirstOrDefault(); s.ImageName = System.IO.Path.GetFileName(upload.FileName); s.ContentType = upload.ContentType; using (var reader = new System.IO.BinaryReader(upload.InputStream)) { s.Content = reader.ReadBytes(upload.ContentLength); } db.Entry(s).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Redirect("/Manage")); }
public ActionResult Enroll(FormCollection fc) { string id = User.Identity.GetUserId(); Student user = db.Students.Where(x => x.Id.Equals(id)).FirstOrDefault(); IEnumerable <Course> list = db.Courses.ToList(); List <Course> selected = new List <Course>(); foreach (var i in list) { if (fc[i.CourseName].First().Equals('t')) { //r += fc[i.CourseName].First() + " "; selected.Add(i); i.Students.Add(user); } } user.Courses = selected; db.SaveChanges(); return(Redirect("/Home/Index")); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { Directory.CreateDirectory(Path.Combine(Server.MapPath("~/UploadedFiles"), user.Id)); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext())); UserManager.AddToRole(user.Id, "Student"); using (MoodleDb db = new MoodleDb()) { Student s = new Student { Id = user.Id, UserName = user.UserName }; db.Students.Add(s); db.SaveChanges(); } await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Enroll", "Student")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public PartialViewResult userQuestionAnswer(CandidateAnswer objCandidateAnswer) { bool IsLast = false; if (Session["co"] == null) { Session["co"] = 1; } else { var i = Convert.ToInt32(Session["co"]); i++; Session["co"] = i; } if (objCandidateAnswer.AnswerText != null) { var ans = (from obj in obQuizDbEntities.Answers where obj.QuestionId.Equals(objCandidateAnswer.QuestionId) select obj).FirstOrDefault(); Result result = new Result(); result.AnswerText = objCandidateAnswer.AnswerText; result.UserId = Session["CandidateName"].ToString(); // result.QuestionId = objCandidateAnswer.QuestionId; result.QuestionId = Convert.ToInt32(Session["questionid"]); obQuizDbEntities.Results.Add(result); obQuizDbEntities.SaveChanges(); } if (objCandidateAnswer.AnswerText != null) { List <CandidateAnswer> objCandidateAnswers = Session["CadQuestionAnswer"] as List <CandidateAnswer>; if (objCandidateAnswers == null) { objCandidateAnswers = new List <CandidateAnswer>(); } objCandidateAnswers.Add(objCandidateAnswer); Session["CadQuestionanswer"] = objCandidateAnswers; } int pageSize = 1; int pageNumber = 0; int CategoryId = Convert.ToInt32(Session["CategoryId"]); if (Session["CadQuestionAnswer"] == null) { pageNumber = pageNumber + 1; } else { List <CandidateAnswer> canAnswer = Session["CanQuestionAnswer"] as List <CandidateAnswer>; pageNumber = Convert.ToInt32(Session["co"]); // pageNumber = canAnswer.Count + 1; //pageNumber = pageNumber + 1; } List <Question> listOfQuestion = new List <Question>(); listOfQuestion = obQuizDbEntities.Questions.Where(model => model.CategoryId == CategoryId).ToList(); if (pageNumber == listOfQuestion.Count) { IsLast = true; var candidate = Session["CandidateName"].ToString(); // Session["co"] = null; } QuestionAnswerViewModel objAnswerViewModel = new QuestionAnswerViewModel(); Question objQuestion = new Question(); objQuestion = listOfQuestion.Skip((pageNumber - 1) * pageSize).Take(pageSize).FirstOrDefault(); objAnswerViewModel.isLast = IsLast; objAnswerViewModel.QuestionId = objQuestion.QuestionId; Session["questionid"] = objQuestion.QuestionId; objAnswerViewModel.QuestionName = objQuestion.QuestionName; objAnswerViewModel.ListOfQuizOptions = (from obj in obQuizDbEntities.Options where obj.QuestionId == objQuestion.QuestionId select new QuizOption() { OptionName = obj.OptionName, OptionId = obj.OptionId }).ToList(); return(PartialView("QuizQuestionOption", objAnswerViewModel)); }