public ActionResult Edit(int id, EditViewModels e, HttpPostedFileBase file) { try { if (file != null) { var bs = new byte[file.ContentLength]; using (var fs = file.InputStream) { var offset = 0; do { offset += fs.Read(bs, offset, bs.Length - offset); } while (offset < bs.Length); } DLSInterface.image = bs; return(View()); } else { SE_ProjectEntities db = new SE_ProjectEntities(); db.Posts.Find(id).Summary = e.summary; db.Posts.Find(id).Details = e.details; db.Posts.Find(id).Picture = DLSInterface.image; db.SaveChanges(); DLSInterface.image = null; return(RedirectToAction("Index")); } } catch { return(View()); } }
// GET: Profile/Edit/5 public ActionResult Edit() { try { if (DLSInterface.loggedEmail == null) { return(RedirectToAction("Login", "Person")); } int idx = DLSInterface.Profileid; ProfileEditViewModels p = new ProfileEditViewModels(); SE_ProjectEntities db = new SE_ProjectEntities(); Profile myprofile = db.Profiles.Find(idx); p.id = myprofile.id; p.Name = myprofile.Name; p.PersonalInfo = myprofile.PersonalInfo; p.ProfilePicture = myprofile.ProfilePicture; DLSInterface.image = myprofile.ProfilePicture; p.RelationshipStatus = myprofile.RelationshipStatus; p.PhoneNumber = myprofile.PhoneNumber; p.Email = myprofile.Email; p.Designation = myprofile.Designation; p.DateOfBirth = myprofile.DateOfBirth; p.Gender = myprofile.Gender; return(View(p)); } catch { return(View()); } }
// GET: Resources/Details/5 public ActionResult Details(int id) { try { MaterialResource s = new MaterialResource(); SE_ProjectEntities db = new SE_ProjectEntities(); foreach (MaterialResource b in db.MaterialResources) { if (b.id == id) { s.Name = b.Name; s.Length = b.Length; s.Content = b.Content; s.id = b.id; s.Type = b.Type; break; } } MemoryStream ms = new MemoryStream(s.Content, 0, 0, true, true); Response.ContentType = s.Type; Response.AddHeader("content-disposition", "attachment;filename=" + s.Name); Response.Buffer = true; Response.Clear(); Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length); Response.OutputStream.Flush(); Response.End(); return(new FileStreamResult(Response.OutputStream, s.Type)); } catch { return(View()); } }
public ActionResult Create(PersonViewModels model) { try { SE_ProjectEntities db = new SE_ProjectEntities(); if (db.TeacherTbls.Any(t => t.Email.Equals(model.email)) || db.StudentTbls.Any(t => t.Email.Equals(model.email))) { ViewBag.Message = "Email Already Taken!"; } else { if (model.isTeacher) { TeacherTbl t = new TeacherTbl(); t.Name = model.name; t.Email = model.email; t.Password = model.password; DLSInterface.loggedEmail = t.Email; db.TeacherTbls.Add(t); db.SaveChanges(); ViewBag.Message = "Success!"; } else { StudentTbl s = new StudentTbl(); s.Name = model.name; s.Email = model.email; s.Password = model.password; DLSInterface.loggedEmail = s.Email; db.StudentTbls.Add(s); db.SaveChanges(); ViewBag.Message = "Success!"; } } if (DLSInterface.loggedEmail != null) { Profile first = new Profile(); first.Email = DLSInterface.loggedEmail; first.Name = null; first.ProfilePicture = null; first.PhoneNumber = null; first.DateOfBirth = null; first.RelationshipStatus = null; first.Designation = null; first.NumberOfClassesEnrolled = DLSInterface.getNumberofClassesEnrolled(first.Email); first.PersonalInfo = null; first.Gender = null; db.Profiles.Add(first); db.SaveChanges(); return(RedirectToAction("ViewClass", "Class")); } return(View()); } catch { return(View()); } }
// GET: Announcement/Delete/5 public ActionResult Delete(int id) { SE_ProjectEntities db = new SE_ProjectEntities(); db.Announcements.Remove(db.Announcements.Find(id)); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult AddClass() { SE_ProjectEntities db = new SE_ProjectEntities(); List <SchoolTbl> SchoolList = db.SchoolTbls.ToList(); ViewBag.SchoolList = new SelectList(SchoolList, "Id", "Name"); ViewBag.Warn = ""; return(View()); }
public ActionResult ViewClass() { DLSInterface.ClassEntered = -1; SE_ProjectEntities db = new SE_ProjectEntities(); List <SchoolTbl> SchoolList = db.SchoolTbls.ToList(); ViewBag.SchoolList = new SelectList(SchoolList, "Id", "Name"); ViewBag.Warn = ""; return(View()); }
// GET: Post/Edit/5 public ActionResult Edit(int id) { EditViewModels l = new EditViewModels(); SE_ProjectEntities db = new SE_ProjectEntities(); Post p = db.Posts.Find(id); DLSInterface.image = p.Picture; l.summary = p.Summary; l.details = p.Details; return(View(l)); }
// GET: Post/Delete/5 public ActionResult Delete(int id) { try { SE_ProjectEntities db = new SE_ProjectEntities(); Post p = db.Posts.Find(id); db.Posts.Remove(p); db.SaveChanges(); return(RedirectToAction("Index", "Post")); } catch { return(RedirectToAction("Index")); } }
// GET: Profile/Delete/5 public ActionResult Delete() { int id = DLSInterface.GetIdByEmail(DLSInterface.loggedEmail); SE_ProjectEntities db = new SE_ProjectEntities(); foreach (Post p in db.Posts) { if (p.email == DLSInterface.loggedEmail) { db.Posts.Remove(p); } } foreach (Profile my in db.Profiles) { if (my.Email == DLSInterface.loggedEmail) { db.Profiles.Remove(my); break; } } if (db.TeacherTbls.Find(id) != null && db.TeacherTbls.Find(id).Email == DLSInterface.loggedEmail) { db.TeacherTbls.Remove(db.TeacherTbls.Find(id)); foreach (TeacherClassOTM totm in db.TeacherClassOTMs) { if (totm.Teacher_Id == id) { db.TeacherClassOTMs.Remove(totm); } } } else { foreach (StudentClassOTM t in db.StudentClassOTMs) { if (t.Student_Id == id) { db.StudentClassOTMs.Remove(t); } } db.StudentTbls.Remove(db.StudentTbls.Find(id)); } db.SaveChanges(); DLSInterface.logout(); return(RedirectToAction("Create", "Person")); }
// GET: Resources public ActionResult Index() { SE_ProjectEntities db = new SE_ProjectEntities(); List <ResourceViewModels> model = new List <ResourceViewModels>(); foreach (MaterialResource m in db.MaterialResources) { if (m.Classid == DLSInterface.ClassEntered) { ResourceViewModels s = new ResourceViewModels(); s.name = m.Name; s.id = m.id; model.Add(s); } } return(View(model)); }
// GET: Profile public ActionResult Index() { int id = DLSInterface.GetIdByEmail(DLSInterface.loggedEmail); if (DLSInterface.loggedEmail == null) { RedirectToAction("Login", "Person"); } SE_ProjectEntities db = new SE_ProjectEntities(); Profile p = new Profile(); foreach (Profile k in db.Profiles) { if (k.Email == DLSInterface.loggedEmail) { p.Email = k.Email; p.Name = k.Name; p.id = k.id; p.NumberOfClassesEnrolled = k.NumberOfClassesEnrolled; p.ProfilePicture = k.ProfilePicture; p.PhoneNumber = k.PhoneNumber; p.DateOfBirth = k.DateOfBirth; p.RelationshipStatus = k.RelationshipStatus; p.Designation = k.Designation; p.PersonalInfo = k.PersonalInfo; p.Gender = k.Gender; break; } } ProfileEditViewModels display = new ProfileEditViewModels(); display.id = p.id; display.Email = p.Email; display.ProfilePicture = p.ProfilePicture; display.PhoneNumber = p.PhoneNumber; display.DateOfBirth = p.DateOfBirth; display.RelationshipStatus = p.RelationshipStatus; display.NumberOfClassesEnrolled = DLSInterface.getNumberofClassesEnrolled(DLSInterface.loggedEmail); display.Designation = p.Designation; display.PersonalInfo = p.PersonalInfo; display.Gender = p.Gender; display.Name = p.Name; DLSInterface.Profileid = display.id; return(View(display)); }
// GET: Announcement public ActionResult Index() { SE_ProjectEntities db = new SE_ProjectEntities(); List <AnnouncementViewModels> ann = new List <AnnouncementViewModels>(); foreach (Announcement a in db.Announcements) { if (a.ClassId == DLSInterface.ClassEntered) { AnnouncementViewModels b = new AnnouncementViewModels(); b.ClassId = a.ClassId; b.id = a.id; b.TeacherId = a.TeacherId; b.Text = a.Text; ann.Add(b); } } return(View(ann)); }
public ActionResult Create(HttpPostedFileBase uploadFile) { byte[] tempFile = new byte[uploadFile.ContentLength]; uploadFile.InputStream.Read(tempFile, 0, uploadFile.ContentLength); SE_ProjectEntities db = new SE_ProjectEntities(); MaterialResource s = new MaterialResource(); s.Content = tempFile; s.Name = uploadFile.FileName; s.Length = uploadFile.ContentLength; s.Type = uploadFile.ContentType; s.TeacherId = DLSInterface.GetIdByEmail(DLSInterface.loggedEmail); s.Classid = DLSInterface.ClassEntered; db.MaterialResources.Add(s); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(AnnouncementViewModels collection) { try { // TODO: Add insert logic here Announcement a = new Announcement(); a.ClassId = DLSInterface.ClassEntered; a.TeacherId = DLSInterface.GetIdByEmail(DLSInterface.loggedEmail); a.Text = collection.Text; SE_ProjectEntities db = new SE_ProjectEntities(); db.Announcements.Add(a); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(HttpPostedFileBase file, string Summary, string Details) { try { if (DLSInterface.loggedEmail == null) { RedirectToAction("Login", "Person"); } SE_ProjectEntities db = new SE_ProjectEntities(); Post p = new Post(); p.class_id = DLSInterface.ClassEntered; p.email = DLSInterface.loggedEmail; p.Summary = Summary; p.Details = Details; if (file != null) { var bs = new byte[file.ContentLength]; using (var fs = file.InputStream) { var offset = 0; do { offset += fs.Read(bs, offset, bs.Length - offset); } while (offset < bs.Length); } p.Picture = bs; } else { p.Picture = null; } db.Posts.Add(p); db.SaveChanges(); return(RedirectToAction("Create", "Post")); } catch { return(View()); } }
public ActionResult Create(SchoolViewModels model) { try { SE_ProjectEntities db = new SE_ProjectEntities(); if (DLSInterface.loggedEmail == null) { ViewBag.Warn = "Please Login First"; } else if (db.TeacherTbls.Any(t => t.Email.Equals(DLSInterface.loggedEmail))) { SchoolTbl s = new SchoolTbl(); s.Name = model.name; if (db.SchoolTbls.Any(S => S.Name.Equals(model.name))) { ViewBag.Warn = "School Already Exists"; } else { db.SchoolTbls.Add(s); db.SaveChanges(); } } else { ViewBag.Warn = "You Must Be Teacher To Register School"; } if (ViewBag.Warn == null) { return(RedirectToAction("Create", "Class")); } return(View("Create")); } catch { return(View()); } }
public ActionResult Edit(ProfileEditViewModels collection, HttpPostedFileBase file) { try { // TODO: Add update logic here if (file != null) { var bs = new byte[file.ContentLength]; using (var fs = file.InputStream) { var offset = 0; do { offset += fs.Read(bs, offset, bs.Length - offset); } while (offset < bs.Length); } DLSInterface.image = bs; return(View()); } else { SE_ProjectEntities db = new SE_ProjectEntities(); db.Profiles.Where(p => p.Email.Equals(DLSInterface.loggedEmail)).FirstOrDefault().Name = collection.Name; db.Profiles.Where(p => p.Email.Equals(DLSInterface.loggedEmail)).FirstOrDefault().Gender = collection.Gender; db.Profiles.Where(p => p.Email.Equals(DLSInterface.loggedEmail)).FirstOrDefault().Designation = collection.Designation; db.Profiles.Where(p => p.Email.Equals(DLSInterface.loggedEmail)).FirstOrDefault().RelationshipStatus = collection.RelationshipStatus; db.Profiles.Where(p => p.Email.Equals(DLSInterface.loggedEmail)).FirstOrDefault().DateOfBirth = collection.DateOfBirth; db.Profiles.Where(p => p.Email.Equals(DLSInterface.loggedEmail)).FirstOrDefault().PhoneNumber = collection.PhoneNumber; db.Profiles.Where(p => p.Email.Equals(DLSInterface.loggedEmail)).FirstOrDefault().PersonalInfo = collection.PersonalInfo; db.Profiles.Where(p => p.Email.Equals(DLSInterface.loggedEmail)).FirstOrDefault().ProfilePicture = DLSInterface.image; db.SaveChanges(); return(RedirectToAction("Index", "Profile")); } } catch { return(View()); } }
public ActionResult Index() { if (DLSInterface.loggedEmail == null) { return(RedirectToAction("Login", "Person")); } SE_ProjectEntities db = new SE_ProjectEntities(); List <PostViewModels> Posts = new List <PostViewModels>(); foreach (Post p in db.Posts) { if (p.class_id == DLSInterface.ClassEntered) { PostViewModels each_post = new PostViewModels(); each_post.Email = p.email; each_post.id = p.id; each_post.Summary = p.Summary; each_post.details = p.Details; each_post.image = p.Picture; Posts.Add(each_post); } } return(View(Posts)); }
public ActionResult Login(LoginViewModels model) { SE_ProjectEntities db = new SE_ProjectEntities(); if (db.TeacherTbls.Any(t => t.Email.Equals(model.email))) { if (db.TeacherTbls.Where(t => t.Email.Equals(model.email)).FirstOrDefault().Password.Equals(model.password)) { DLSInterface.loggedEmail = db.TeacherTbls.Where(t => t.Email.Equals(model.email)).FirstOrDefault().Email; } else { ViewBag.Message = "Email or Password Doesn't match"; } } else if (db.StudentTbls.Any(t => t.Email.Equals(model.email))) { if (db.StudentTbls.Where(t => t.Email.Equals(model.email)).FirstOrDefault().Password.Equals(model.password)) { DLSInterface.loggedEmail = db.StudentTbls.Where(t => t.Email.Equals(model.email)).FirstOrDefault().Email; } else { ViewBag.Message = "Email or Password Doesn't match"; } } else { ViewBag.Message = "Email not Registered"; } if (DLSInterface.loggedEmail != null) { return(RedirectToAction("ViewClass", "Class")); } return(View()); }
public JsonResult GetClassList(string schoolName) { SE_ProjectEntities db = new SE_ProjectEntities(); if (!db.SchoolTbls.Any(s => s.Name.Equals(schoolName))) { List <string> classListEmpty = new List <string>(); return(Json(classListEmpty, JsonRequestBehavior.AllowGet)); } int schoolId = db.SchoolTbls.Where(s => s.Name.Equals(schoolName)).FirstOrDefault().Id; db.Configuration.ProxyCreationEnabled = false; //List<ClassTbl> ClassList = db.ClassTbls.Where(x => x.School_Id == schoolId).ToList(); List <string> classList = new List <string>(); foreach (ClassTbl c in db.ClassTbls) { if (c.School_Id == schoolId) { classList.Add(c.Name); } } return(Json(classList, JsonRequestBehavior.AllowGet)); }
public ActionResult AddClass(ViewClassViewModels model) { try { SE_ProjectEntities db = new SE_ProjectEntities(); List <SchoolTbl> SchoolList = db.SchoolTbls.ToList(); ViewBag.SchoolList = new SelectList(SchoolList, "Id", "Name"); if (DLSInterface.loggedEmail == null) { ViewBag.Warn = "Login First"; return(View()); } else if (db.TeacherTbls.Any(t => t.Email.Equals(DLSInterface.loggedEmail))) { int teacherId = db.TeacherTbls.Where(t => t.Email.Equals(DLSInterface.loggedEmail)).FirstOrDefault().Id; int classId = db.ClassTbls.Where(c => c.Name.Equals(model.className)).FirstOrDefault().Id; string classCode = db.ClassTbls.Where(c => c.Name.Equals(model.className)).FirstOrDefault().Code; bool isExist = false; foreach (TeacherClassOTM tc in db.TeacherClassOTMs) { if (tc.Teacher_Id == teacherId && tc.Class_Id == classId) { isExist = true; } } if (isExist) { ViewBag.Warn = "Already Registered in Class"; return(View()); } else { TeacherClassOTM tc = new TeacherClassOTM(); tc.Teacher_Id = teacherId; tc.Class_Id = classId; if (classCode.Equals(model.classCode)) { db.TeacherClassOTMs.Add(tc); db.SaveChanges(); ViewBag.Warn = "Success!"; return(View()); } else { ViewBag.Warn = "Invalid code!"; return(View()); } } } else if (db.StudentTbls.Any(t => t.Email.Equals(DLSInterface.loggedEmail))) { int studentId = db.StudentTbls.Where(s => s.Email.Equals(DLSInterface.loggedEmail)).FirstOrDefault().Id; int classId = db.ClassTbls.Where(c => c.Name.Equals(model.className)).FirstOrDefault().Id; string classCode = db.ClassTbls.Where(c => c.Name.Equals(model.className)).FirstOrDefault().Code; bool isExist = false; foreach (StudentClassOTM sc in db.StudentClassOTMs) { if (sc.Student_Id == studentId && sc.Class_Id == classId) { isExist = true; break; } } if (isExist) { ViewBag.Warn = "Already Registered in Class"; return(View()); } else { StudentClassOTM sc = new StudentClassOTM(); sc.Student_Id = studentId; sc.Class_Id = classId; if (classCode.Equals(model.classCode)) { db.StudentClassOTMs.Add(sc); db.SaveChanges(); ViewBag.Warn = "Success!"; return(View()); } else { ViewBag.Warn = "Invalid code!"; return(View()); } } } return(View()); } catch { return(View()); } }
public ActionResult ViewClass(ViewClassViewModels model) { try { SE_ProjectEntities db = new SE_ProjectEntities(); List <SchoolTbl> SchoolList = db.SchoolTbls.ToList(); ViewBag.SchoolList = new SelectList(SchoolList, "Id", "Name"); if (DLSInterface.loggedEmail == null) { ViewBag.Warn = "Login First"; return(View()); } else if (db.TeacherTbls.Any(t => t.Email.Equals(DLSInterface.loggedEmail))) { int teacherId = db.TeacherTbls.Where(t => t.Email.Equals(DLSInterface.loggedEmail)).FirstOrDefault().Id; int classId = db.ClassTbls.Where(c => c.Name.Equals(model.className)).FirstOrDefault().Id; bool isExist = false; foreach (TeacherClassOTM tc in db.TeacherClassOTMs) { if (tc.Teacher_Id == teacherId && tc.Class_Id == classId) { isExist = true; } } if (!isExist) { ViewBag.Warn = "Not Registered in Class"; return(View()); } } else if (db.StudentTbls.Any(t => t.Email.Equals(DLSInterface.loggedEmail))) { int studentId = db.StudentTbls.Where(s => s.Email.Equals(DLSInterface.loggedEmail)).FirstOrDefault().Id; int classId = db.ClassTbls.Where(c => c.Name.Equals(model.className)).FirstOrDefault().Id; bool isExist = false; foreach (StudentClassOTM sc in db.StudentClassOTMs) { if (sc.Student_Id == studentId && sc.Class_Id == classId) { isExist = true; } } if (!isExist) { ViewBag.Warn = "Not Registered in Class"; return(View()); } } else { int schoolId = db.SchoolTbls.Where(s => s.Name.Equals(model.schoolName)).FirstOrDefault().Id; bool isexist = false; foreach (ClassTbl cl in db.ClassTbls) { if (cl.School_Id == schoolId && cl.Name == model.className) { isexist = true; } } if (!isexist) { ViewBag.Warn = "Class Not Found"; return(View()); } } int actualClassId = -1; foreach (ClassTbl c in db.ClassTbls) { if (c.School_Id.ToString().Equals(model.schoolName) && c.Name.Equals(model.className)) { actualClassId = c.Id; } } DLSInterface.ClassEntered = actualClassId; return(RedirectToAction("Index", "Post")); } catch { return(View()); } }
public ActionResult Create(ClassViewModels model) { try { SE_ProjectEntities db = new SE_ProjectEntities(); if (DLSInterface.loggedEmail == null) { ViewBag.Warn = "Please Login First"; } else if (db.TeacherTbls.Any(t => t.Email.Equals(DLSInterface.loggedEmail))) { ClassTbl c = new ClassTbl(); c.Name = model.name; c.School_Id = db.SchoolTbls.Where(s => s.Name.Equals(model.schoolName)).FirstOrDefault().Id; c.Code = model.classCode; bool isexist = false; foreach (ClassTbl cls in db.ClassTbls) { if (cls.Name == model.name && cls.School_Id == c.School_Id) { isexist = true; } } if (!isexist) { db.ClassTbls.Add(c); db.SaveChanges(); } int teacherId = db.TeacherTbls.Where(t => t.Email.Equals(DLSInterface.loggedEmail)).FirstOrDefault().Id; int classId = db.ClassTbls.Where(C => C.Name.Equals(model.name)).FirstOrDefault().Id; bool isExist = false; foreach (TeacherClassOTM tc in db.TeacherClassOTMs) { if (tc.Teacher_Id == teacherId && tc.Class_Id == classId) { isExist = true; } } if (isExist) { ViewBag.Warn = "Already Exists"; } else { TeacherClassOTM tc = new TeacherClassOTM(); tc.Teacher_Id = teacherId; tc.Class_Id = classId; db.TeacherClassOTMs.Add(tc); db.SaveChanges(); ViewBag.Warn = "Success"; } } else { ViewBag.Warn = "You Must Be Teacher To Register Class"; } return(View("Create")); } catch { return(View()); } }