예제 #1
0
        public IActionResult Add(Activity Act)
        {
            if (ModelState.IsValid == false)
            {
                ViewBag.Errors = ModelState.Values;
                ViewBag.Status = true;
                return(View("AddPage"));
            }
            else
            {
                if (Act.date < DateTime.Now.Date)
                {
                    TempData["message"] = "Date cant be in the past";
                    return(RedirectToAction("AddPage"));
                }
                else
                {
                    Act.created_at = DateTime.Now;
                    Act.updated_at = DateTime.Now;
                    Act.userId     = (int)HttpContext.Session.GetInt32("UserId");
                    _context.Add(Act);
                    _context.SaveChanges();
                    TempData["message"] = "Sucessfully added a new activity";
                }
                // TempData["message"] = "Unsucessful in adding a new activity";
            }
            Activity Activity = new Activity();

            Activity = _context.activities.Where(activity => activity.created_at.Ticks == Act.created_at.Ticks).SingleOrDefault();
            int ID = Activity.id;

            return(RedirectToAction("Page", new { @ActId = ID }));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("StudentId,StudentName,Class,Father,Picture")] Students students)
        {
            if (ModelState.IsValid)
            {
                _context.Add(students);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(students));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("QuestionId,QuestionName,Mark,ExamId")] Question question)
        {
            if (ModelState.IsValid)
            {
                _context.Add(question);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ExamId"] = new SelectList(_context.Exams, "ExamId", "ExamId", question.ExamId);
            return(View(question));
        }
예제 #4
0
        public IActionResult register(string first_name, string last_name, string email, string password, string passwordC)
        {
            // Do something with form input
            Console.WriteLine("Registration Attempted: " + first_name + " | " + last_name + " | " + email + " | " + password + " | " + passwordC);
            Users ReturnedUser = _context.Users.Where(user => user.Email == email)
                                 .SingleOrDefault();

            var regexItem = new Regex("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$");

            if (ReturnedUser != null)
            {
                ViewBag.RegisterError = "User already Exists!";
                return(View("Index"));
            }
            else if (password != passwordC)
            {
                ViewBag.RegisterError = "Passwords do not match!";
                return(View("Index"));
            }
            else if (first_name.All(char.IsDigit) || last_name.All(char.IsDigit))
            {
                ViewBag.RegisterError = "First & Last name must not contain any special characters or numbers!";
                return(View("Index"));
            }
            else if (password.Length < 8 || passwordC.Length < 8)
            {
                ViewBag.RegisterError = "Passwords is not long enough!";
                return(View("Index"));
            }
            else if (!regexItem.IsMatch(password))
            {
                ViewBag.RegisterError = "Invalid Password!";
                return(View("Index"));
            }


            //add user to db and render home page
            Users NewUser = new Users
            {
                FirstName = first_name,
                LastName  = last_name,
                Email     = email,
                Password  = password,
            };

            _context.Add(NewUser);
            _context.SaveChanges();

            HttpContext.Session.SetString("email", email);
            HttpContext.Session.SetString("first_name", first_name);
            HttpContext.Session.SetInt32("id", NewUser.UserId);
            return(RedirectToAction("Home"));
        }
예제 #5
0
 public IActionResult Register(RegisterViewModel model)
 {
     if (_context.users.Where(u => u.email == model.email).SingleOrDefault() != null)
     {
         TempData["message"] = "Email is taken!";
         return(RedirectToAction("Index"));
     }
     else
     {
         if (ModelState.IsValid)
         {
             User NewUser = new User {
                 first_name = model.first_name,
                 last_name  = model.last_name,
                 email      = model.email,
                 password   = model.password
             };
             NewUser.created_at = DateTime.Now;
             NewUser.updated_at = DateTime.Now;
             _context.Add(NewUser);
             _context.SaveChanges();
             User current = _context.users.Where(u => u.email == model.email).SingleOrDefault();
             HttpContext.Session.SetInt32("UserId", current.id);
             TempData["message"] = "You have successfully registered!";
             return(RedirectToAction("Activity", "Activity"));
         }
         ViewBag.Errors = ModelState.Values;
         ViewBag.Status = true;
         return(View("Index"));
     }
 }
예제 #6
0
        public async Task <IActionResult> Create([Bind("ID,LastName,FirstMidName")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
        public async Task <IActionResult> Create([Bind("TeacherId,TeacherName")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teacher);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(teacher));
        }
예제 #8
0
        public async Task <IActionResult> Create([Bind("id,corse_title,credit_hours")] Subject subject)
        {
            if (ModelState.IsValid)
            {
                _context.Add(subject);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(subject));
        }
        public async Task <IActionResult> Create([Bind("AnswerId,AnswerName,IsRightAnswer,QuestionId")] Answer answer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(answer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["QuestionId"] = new SelectList(_context.Questions, "QuestionId", "QuestionId", answer.QuestionId);
            return(View(answer));
        }
        public async Task <IActionResult> Create([Bind("ExamId,ExamType,StartDate,EndDate,SubjectId")] Exam exam)
        {
            if (ModelState.IsValid)
            {
                _context.Add(exam);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SubjectId"] = new SelectList(_context.Subjects, "SubjectId", "SubjectId", exam.SubjectId);
            return(View(exam));
        }
예제 #11
0
        public async Task <IActionResult> Create([Bind("SubjectCode,SubjectName,StudentId")] Subjects subjects)
        {
            if (ModelState.IsValid)
            {
                _context.Add(subjects);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StudentId"] = new SelectList(_context.Students, "StudentId", "Class", subjects.StudentId);
            return(View(subjects));
        }
예제 #12
0
        public async Task <IActionResult> Create([Bind("TopicsCode,TopicsName,SubjectCode")] Topics topics)
        {
            if (ModelState.IsValid)
            {
                _context.Add(topics);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SubjectCode"] = new SelectList(_context.Subjects, "SubjectCode", "SubjectCode", topics.SubjectCode);
            return(View(topics));
        }
예제 #13
0
 public IActionResult CreateUser(User user)
 {
     if (ModelState.IsValid)
     {
         if (dbContext.Users.Any(u => u.Email == user.Email))
         {
             ModelState.AddModelError("Email", "Email already taken");
             return(View("Index"));
         }
         PasswordHasher <User> Hasher = new PasswordHasher <User>();
         user.Password = Hasher.HashPassword(user, user.Password);
         dbContext.Add(user);
         dbContext.SaveChanges();
         HttpContext.Session.SetInt32("userID", user.UserID);
         return(RedirectToAction("Dashboard"));
     }
     else
     {
         return(View("Index"));
     }
 }
예제 #14
0
        public async Task <IActionResult> Create([Bind("AnswerSerial,Answer,Correct,QuestionNo")] Answers answers)
        {
            if (ModelState.IsValid)
            {
                _context.Add(answers);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["QuestionNo"] = new SelectList(_context.Questions, "QuestionNo", "QuestionNo", answers.QuestionNo);
            return(View(answers));
        }
예제 #15
0
        public async Task <IActionResult> Create([Bind("QuestionNo,Question,TopicsCode")] Questions questions)
        {
            if (ModelState.IsValid)
            {
                _context.Add(questions);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TopicsCode"] = new SelectList(_context.Topics, "TopicsCode", "TopicsCode", questions.TopicsCode);
            return(View(questions));
        }
예제 #16
0
        public IActionResult Scan(string url, int depth)
        {
            ViewBag.Results = ScanHelper.GetResultFromUrlWithDepth(url, depth);
            var pages = ScanHelper.GetSavedPages();

            foreach (var page in pages)
            {
                _context.Add(page);
            }

            _context.SaveChanges();
            return(View());
        }
        public async Task <IActionResult> Create([Bind("ResultId,TotalMarks,ExamId,StudentId")] ExamResult examResult)
        {
            if (ModelState.IsValid)
            {
                _context.Add(examResult);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ExamId"]    = new SelectList(_context.Exams, "ExamId", "ExamId", examResult.ExamId);
            ViewData["StudentId"] = new SelectList(_context.Students, "StudentId", "StudentId", examResult.StudentId);
            return(View(examResult));
        }
예제 #18
0
        public HomeController(ExamContext context)
        {
            this._context = context;

            if (!_context.Exams.Any())
            {
                _context.Add(new Exam()
                {
                    Counter = 1
                });
                _context.SaveChanges();
            }
        }
예제 #19
0
        private async Task AddOrUpdateProcessAsync(int moduleType, int subType = 0, int number = 0)
        {
            var process = await _examContext.ExamProcesss.SingleOrDefaultAsync();

            if (process == null)
            {
                process            = new ExamProcess();
                process.SubType    = subType;
                process.ModuleType = moduleType;
                process.Number     = number;
                process.AddTime    = DateTime.Now;
                _examContext.Add(process);
            }
            else
            {
                process.ModuleType = moduleType;
                process.SubType    = subType;
                process.Number     = number;
                process.AddTime    = DateTime.Now;
                _examContext.Update(process);
            }
            await _examContext.SaveChangesAsync();
        }