public TeacherIndexViewModel(int teacherID, KnowledgeChannelEntities db) { // TODO: Complete member initialization _teacherID = teacherID; PopulateTeacher(teacherID, db); PopulateResourcesFromTeacherId(teacherID, db); }
public ActionResult CreateAdmin(Admin admin) { if (!Application.IsAuthenticated && Application.AdminType != 1) { ViewBag.Header = "Authorization Level Too Low"; ViewBag.Message = "Your authorization is not valid for this type of operation"; return View("Message", "_LayoutGuest"); } if (!admin.Email.IsEmail()) { ViewBag.Header = "Inputs were incorrect"; ViewBag.Message = "Please go back to the form and input the correct data"; return View("Message", "_LayoutAdmin"); } //Airah's Code using (KnowledgeChannelEntities context = new KnowledgeChannelEntities()) { if (ModelState.IsValid) { admin.Password = Encrypt.ComputeHash(admin.Password, "SHA512", null); admin.DateCreated = DateTime.Now; context.AddToAdmins(admin); context.SaveChanges(); return RedirectToAction("ViewAdmins"); } } return View(); }
public ResourcePageViewModel(int levelId, int subjectId, KnowledgeChannelEntities knowledgeChannelEntities) { // TODO: Complete member initialization this.levelId = levelId; this.subjectId = subjectId; this.db = knowledgeChannelEntities; }
public ResourcePageViewModel(KnowledgeChannelEntities knowledgeChannelEntities) { // TODO: Complete member initialization this.db = knowledgeChannelEntities; LevelName = "Knowledge Channel"; SubjectName = "Resources"; Resources = db.Resources.Where(x => x.LevelID == 4).ToList(); }
public JsonResult AutoComplete(string searchText) { db = new KnowledgeChannelEntities(); List<School> schoolList; IQueryable<School> schools = db.Schools; schoolList = schools.Where(x => x.SchoolName.Contains(searchText)).Take(5).ToList(); return Json((from school in schoolList select new { SchoolID = school.SchoolID, SchoolName = school.SchoolName })); }
private void PopulateResourcesFromTeacherId(int teacherId, KnowledgeChannelEntities db) { var model = db.Resources.Where(x => x.TeacherID == teacherId); // Resources PopulateResources(model); // Feedback Responses IQueryable<KChOTS.Feedback> allFeedbacks = db.Feedbacks; Feedbacks = allFeedbacks.Where(x => x.TeacherID == teacherId && x.IsResponded == true && x.IsRead == false).ToList(); }
private void PopulateTeacher(int teacherID, KnowledgeChannelEntities db) { IQueryable<KChOTS.Teacher> allTeachers = db.Teachers; var teacher = allTeachers.Where(x => x.TeacherID == teacherID).SingleOrDefault(); Teacher = new TeacherDataModel(); Teacher.FirstName = teacher.FirstName; Teacher.LastName = teacher.LastName; Teacher.Email = teacher.Email; }
public FeedbackViewModel(KnowledgeChannelEntities db, int feedbackID, int teacherID) { _db = db; _feedbackId = feedbackID; _teacherId = teacherID; IQueryable<KChOTS.Feedback> feedbacks = _db.Feedbacks; var specific = feedbacks.Where(x => x.ID == _feedbackId && x.TeacherID == _teacherId).SingleOrDefault(); specific.IsRead = true; SpecificFeedback = new FeedbackDataModel() { Feedback = specific }; db.SaveChanges(); }
private void SaveInDatabase(AdminUploadViewModel Model, string path, int adminId, KnowledgeChannelEntities db) { var resource = db.Resources.CreateObject(); resource.DateCreated = DateTime.Now; resource.Name = Model.Resource.Name; resource.Description = Model.Resource.Description; resource.ResourceFile = path; resource.LevelID = 4; resource.AdminID = adminId; db.Resources.AddObject(resource); db.SaveChanges(); }
public FeedbackViewModel(KnowledgeChannelEntities db) { _db = db; IQueryable<KChOTS.Feedback> feedbacks = _db.Feedbacks; List<FeedbackDataModel> model = new List<FeedbackDataModel>(); foreach (var feedback in feedbacks.Where(x => x.IsResponded == false)) { KChOTS.Teacher teacher = _db.Teachers.Where(x => x.TeacherID == feedback.TeacherID).SingleOrDefault(); model.Add(new FeedbackDataModel() { Feedback = feedback, Teacher = teacher }); } Feedback = model; }
private void PopulateLevelsAndSubjects(KnowledgeChannelEntities db) { List<SelectListItem> subjects = new List<SelectListItem>(); List<SelectListItem> levels = new List<SelectListItem>(); foreach (var subject in db.Subjects.ToList()) { subjects.Add(new SelectListItem() { Text = subject.SubjectName, Value = subject.SubjectID.ToString() }); } foreach (var level in db.Levels.Where(x=>x.LevelID != 4).ToList()) { levels.Add(new SelectListItem() { Text = level.LevelName, Value = level.LevelID.ToString() }); } Subjects = subjects; Levels = levels; }
public ActionResult DeleteAdmin(Admin model) { if (!Application.IsAuthenticated && Application.AdminType != 1) { ViewBag.Header = "Authorization Level Too Low"; ViewBag.Message = "Your authorization is not valid for this type of operation"; return View("Message", "_LayoutGuest"); } int adminid = model.AdminID; using (KnowledgeChannelEntities context = new KnowledgeChannelEntities()) { Admin admin = context.Admins.Where(a => a.AdminID == adminid).Single(); context.DeleteObject(admin); context.SaveChanges(); return RedirectToAction("ViewAdmins"); } }
public void SaveFile(AdminUploadViewModel model, HttpServerUtilityBase server, int adminId, KnowledgeChannelEntities db) { var file = model.Resource.ResourceFile; if (file.ContentLength > 0) { var admin = db.Teachers.Where(x => x.TeacherID == adminId).SingleOrDefault(); var fileName = Path.GetFileName(file.FileName); var folderName = Path.Combine(server.MapPath("~/FileResources"), "KnowledgeChannel"); var folderNameTosave = Path.Combine("FileResources", "KnowledgeChannel"); if (!Directory.Exists(folderName)) { Directory.CreateDirectory(folderName); } var pathFileServer = Path.Combine(folderName, fileName); file.SaveAs(pathFileServer); var pathDatabase = Path.Combine(folderNameTosave, fileName); SaveInDatabase(model, pathDatabase, adminId, db); } }
private void PopulateResourcesFromTeacherId(int teacherId, KnowledgeChannelEntities db) { var model = db.Resources.Where(x => x.TeacherID == teacherId); List<ResourceDataModel> resources = new List<ResourceDataModel>(); foreach (var item in model) { resources.Add(new ResourceDataModel() { ID = item.ID, Name = item.Name, Description = item.Description, ResourceFilePath = item.ResourceFile, DateCreated = (DateTime)item.DateCreated }); } Resources = resources; }
public ActionResult Register(TeacherViewModel model) { _db = new KnowledgeChannelEntities(); bool emailExists = _db.Teachers.Where(x => x.Email == model.Teacher.Email).ToList().Count > 0; if (emailExists) { ModelState.AddModelError("EmailExists", "Email is already taken"); } if (!model.Teacher.Email.IsEmail()) { ModelState.AddModelError("EmailWrongFormat", "Email is not in correct format"); } if (!model.Teacher.ContactNumber.IsNumeric()) { ModelState.AddModelError("ContactNotNumeric", "Not a valid contact number"); } if (model.Teacher.Gender == null || model.Teacher.Email == null || model.Teacher.LastName == null || model.Teacher.FirstName == null || model.Teacher.Password == null){ ModelState.AddModelError("InputRequired", "Please fill up the required fields"); } if (model.Teacher.Password != model.Teacher.ConfirmPassword) ModelState.AddModelError("PasswordsDoNotMatch", "Passwords do not match"); if (model.Teacher.Password.Length < 6) ModelState.AddModelError("PasswordsDoNotMatch", "Password must at least have 6 characters"); if (model.Teacher.SchoolID == 0) ModelState.AddModelError("NoSchoolSelected", "School not selected correctly. Please retry inputting your school"); if (!ModelState.IsValid){ return View(new TeacherViewModel()); } RegisterTeacher(model); return RedirectToAction("SignIn"); }
public TeacherResourcesViewModel(int teacherId, KnowledgeChannelEntities db) { PopulateResourcesFromTeacherId(teacherId, db); }
public ActionResult ViewAdmins() { if (!Application.IsAuthenticated && Application.AdminType != 1) { ViewBag.Header = "Authorization Level Too Low"; ViewBag.Message = "Your authorization is not valid for this type of operation"; return View("Message", "_LayoutGuest"); } using (KnowledgeChannelEntities context = new KnowledgeChannelEntities()) { IEnumerable<Admin> List = context.Admins.ToList(); return View(List); } }
private void SaveInDatabase(TeacherUploadViewModel Model,string path, int TeacherID, KnowledgeChannelEntities db) { var resource = db.Resources.CreateObject(); resource.DateCreated = DateTime.Now; resource.Name = Model.Resource.Name; resource.Description = Model.Resource.Description; resource.ResourceFile = path; resource.LevelID = Model.Resource.ResourceLevel; resource.SubjectID = Model.Resource.ResourceSubject; resource.TeacherID = TeacherID; db.Resources.AddObject(resource); db.SaveChanges(); }
//POST public TeacherUploadViewModel(TeacherUploadViewModel model, KnowledgeChannelEntities db) { this.model = model; Message = "Thank you. Your file has been uploaded."; PopulateLevelsAndSubjects(db); }
public ActionResult ViewArticle() { using (KnowledgeChannelEntities context = new KnowledgeChannelEntities()) { IEnumerable<ContentPage> List = context.ContentPages.ToList(); return View(List); } }
//VIEW public TeacherUploadViewModel(KnowledgeChannelEntities db) { PopulateLevelsAndSubjects(db); }
public ActionResult SignIn(string email, string password) { //TODO: Authenticate user _db = Application.Db; var User = _db.Teachers.Where(x => x.Email == email).FirstOrDefault(); if (User == null || !Encrypt.VerifyHash(password, "SHA512",User.Password)) { ModelState.AddModelError("UserNotFound", "Email or Password is incorrect"); return View(); } if (Session["TeacherID"] != null) { Session.Remove("TeacherID"); } Session.Add("TeacherID", User.TeacherID); //TODO: Session Handling, Authorization Tokens //TODO: Redirect to Index page //TODO: Create Model for Index/Home Page return RedirectToAction("Index"); }
public TeacherViewModel() { _db = new KnowledgeChannelEntities(); PopulateGenders(); PopulateRegions(); }
public ContentViewModel(KnowledgeChannelEntities knowledgeChannelEntities) { // TODO: Complete member initialization this.db = knowledgeChannelEntities; }
public ActionResult EditAdmin(Admin model) { if (!Application.IsAuthenticated && Application.AdminType != 1) { ViewBag.Header = "Authorization Level Too Low"; ViewBag.Message = "Your authorization is not valid for this type of operation"; return View("Message", "_LayoutAdmin"); } if (!model.Email.IsEmail()) { ViewBag.Header = "Inputs were incorrect"; ViewBag.Message = "Please go back to the form and input the correct data"; return View("Message", "_LayoutAdmin"); } using (KnowledgeChannelEntities context = new KnowledgeChannelEntities()) { if (model.Username == null && model.Password == null) { ModelState.AddModelError("NullError", "Username and Password fields cannot be empty"); } if (ModelState.IsValid) { Admin admin = context.Admins.Where(a => a.AdminID == model.AdminID).Single(); admin.AdminType = model.AdminType; admin.Username = model.Username; admin.Password = Encrypt.ComputeHash(model.Password,"SHA512",null); admin.LastName = model.LastName; admin.FirstName = model.FirstName; admin.ContactNo = model.ContactNo; admin.Email = model.Email; admin.DateCreated = model.DateCreated; context.SaveChanges(); return RedirectToAction("ViewAdmins"); } return View(); } }
public AdminUploadViewModel(AdminUploadViewModel model, KnowledgeChannelEntities db) { this.model = model; }