// To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CourseExists(Course.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            string webRootPath = _hostingEnvironment.WebRootPath;
            var    files       = HttpContext.Request.Form.Files; // get, post, put, etc....

            if (User.ID != 0)
            { // existing user
                var objFromDb = await _context.User.FindAsync(User.ID);

                if (files.Count > 0)
                {
                    string fileName  = Guid.NewGuid().ToString();
                    var    uploads   = Path.Combine(webRootPath, @"img\profile");
                    var    extension = Path.GetExtension(files[0].FileName);

                    var imagePath = Path.Combine(webRootPath, objFromDb.ProfilePic.TrimStart('\\'));
                    if (System.IO.File.Exists(imagePath))
                    {
                        System.IO.File.Delete(imagePath);
                    }

                    using (var fileStream = new FileStream(Path.Combine(uploads, fileName + extension), FileMode.Create))
                    {
                        files[0].CopyTo(fileStream);
                    }

                    User.ProfilePic = @"\img\profile\" + fileName + extension;
                }
                else
                {
                    User.ProfilePic = objFromDb.ProfilePic;  // no image uploaded, just readding it from db so we don't lose it
                }
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(User.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 3
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Assignment.Add(Assignment);
            await _context.SaveChangesAsync();

            Assignment = _context.Assignment.OrderByDescending(x => x.ID).FirstOrDefault();

            Models.Notification NotificationObj = new Models.Notification();

            NotificationObj.sourceID = Assignment.ID;
            NotificationObj.Type     = 'A';
            NotificationObj.Message  = "Assignment: " + Assignment.Title + " Has been Created";

            _context.Notification.Add(NotificationObj);

            await _context.SaveChangesAsync();

            return(RedirectToPage("./LoggedInHomePage"));
        }
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            int userId       = (int)HttpContext.Session.GetInt32(SD.UserSessionId);
            var isInstructor = await _context.User.Where(x => x.ID == userId).Where(x => x.UserType == 'I').AnyAsync();

            if (!isInstructor)
            {
                return(NotFound());
            }


            courseHelper             = new CourseHelper();
            courseValidationResponse = new CourseValidationResponse();

            Course.InstructorID = userId;

            courseValidationResponse = courseHelper.ValidateCourse(Course);

            if (userId == null)
            {
                userId = 0;
            }

            //If user is not logged in or is not an instructor or the instructorId for the course is not the ID of the user, return unauthorized
            if (userId == 0 || !isInstructor || Course.InstructorID != userId)
            {
                return(Unauthorized());
            }

            //Make sure that start time is before the end time
            if (courseValidationResponse.isValidated)
            {
                _context.Course.Add(Course);
                await _context.SaveChangesAsync();
            }
            //TODO: Make error page



            return(RedirectToPage("./Index"));
        }
Esempio n. 5
0
        public async Task <IActionResult> OnPostAsync()
        {
            int             id       = (int)HttpContext.Session.GetInt32(SD.UserSessionId);
            PayBillResponse response = await stripeHelper.PayBill(billingSubmission);

            if (response.responseMessage.StatusCode != HttpStatusCode.OK)
            {
                return(RedirectToPage("./Billing/PaymentFailed"));
            }
            else
            {
                StudentPayment studentPayment = new StudentPayment();
                studentPayment.StudentId     = id;
                studentPayment.StripeTokenId = response.studentPayments.StripeTokenId;
                studentPayment.Payment       = response.studentPayments.Payment;
                studentPayment.CreatedOn     = DateTime.UtcNow;
                await _context.StudentPayments.AddAsync(studentPayment);

                await _context.SaveChangesAsync();

                return(RedirectToPage("./Billing/PaymentSuccessful"));
            }
        }