Exemple #1
0
        // Delete a review
        public async Task <IActionResult> OnGetDeleteAsync(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            // find review
            var review = await _context.Review.FindAsync(id);

            // review not found
            if (Review == null)
            {
                return(NotFound());
            }

            // delete review
            try {
                _context.Review.Remove(review);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            catch (DbUpdateException) {
                return(RedirectToAction("./Index",
                                        new { id, saveChangesError = true }));;
            }
        }
Exemple #2
0
        public async Task <IActionResult> CreateReview(Review review)
        {
            // check for any model errors
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Review.Add(review);
            await _context.SaveChangesAsync();

            return(Ok(review));
        }
Exemple #3
0
        public async Task <IActionResult> OnPostAsync(long id)
        {
            var reviewToUpdate = await _context.Review.FindAsync(id);

            // no review found
            if (reviewToUpdate == null)
            {
                return(NotFound());
            }

            reviewToUpdate.Rating = Convert.ToInt32(Request.Form["rating"]);

            if (await TryUpdateModelAsync <Review>(
                    reviewToUpdate,
                    "review",
                    s => s.Description, s => s.Rating))
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            return(Page());
        }
Exemple #4
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var userToUpdate = await _context.Users.FindAsync(UserData.Id);

            if (userToUpdate == null)
            {
                return(NotFound());
            }

            // update user info
            userToUpdate.Email      = UserData.Email;
            userToUpdate.StudentId  = UserData.StudentId;
            userToUpdate.EmployeeId = UserData.EmployeeId;
            await _context.SaveChangesAsync();

            return(RedirectToPage("/Index"));
        }
Exemple #5
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Users.Password = BCrypt.Net.BCrypt.HashPassword(Users.Password);

            // check for the current enrollment status of the new user
            if (Request.Form["UserType"] == "Student")
            {
                Users.TypeId = 1;
            }
            else if (Request.Form["UserType"] == "Faculty")
            {
                Users.TypeId = 2;
            }
            else
            {
                Users.TypeId = 3;
            }

            _context.Add(new Users {
                FirstName = Users.FirstName,
                LastName  = Users.LastName,
                Password  = Users.Password,
                Email     = Users.Email,
                TypeId    = Users.TypeId
            });
            await _context.SaveChangesAsync();

            // log in user and setup a session
            HttpContext.Session.Clear();
            HttpContext.Session.Remove("_email");
            HttpContext.Session.SetString("_email", Users.Email);
            return(RedirectToPage("/Index"));
        }