Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Review).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReviewExists(Review.ReviewID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Classes.Add(Class);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Student.StudentID = 2459013;
            _context.Students.Add(Student);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Review = await _context.Reviews.FindAsync(id);

            if (Review != null)
            {
                _context.Reviews.Remove(Review);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            // @await Html.PartialAsync("_LoginPartial")
            //int code = User.Identity.GetHashCode();
            //Review.Score = code;

            // Need to get username as string somehow from AccountController

            // 1How to look up Review.StudentID from authenticated user?
            //2 How to relate user's StudentID to Student table?
            string uname;
            {
                System.IO.StreamReader file = new System.IO.StreamReader(@"uname.txt");
                uname = file.ReadLine();
                file.Close();
            }
            int studentID = 0;
            //FILEIO
            int n = _context.Students.Count();

            {
                List <Student> students = _context.Students.ToList();
                for (int i = 0; i < students.Count; i++)
                {
                    if (students[i].LastName == uname)
                    {
                        studentID = students[i].StudentID;
                        break;
                    }
                }
            }
            if (studentID == 0)
            {
                Student stu = new Student();
                //stu.StudentID = i+1;
                stu.FirstMidName = uname;
                stu.LastName     = uname;
                _context.Students.Add(stu);
                _context.SaveChanges();

                List <Student> students = _context.Students.ToList();
                studentID = students[0].StudentID;
                for (int i = 0; i < students.Count; i++)
                {
                    if (students[i].LastName == uname)
                    {
                        studentID = students[i].StudentID;
                        break;
                    }
                }
            }
            // return RedirectToPage("./Index");

            Review.StudentID = studentID;
            _context.Reviews.Add(Review);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }