コード例 #1
0
        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();
        }
コード例 #2
0
 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();
 }
コード例 #3
0
 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();
 }
コード例 #4
0
 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");
     }
 }
コード例 #5
0
        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();
            }
        }
 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();
 }