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()); } }
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: 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")); }
// 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")); }
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 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(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 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()); } }
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()); } }