public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } //remove the section from the session List <CourseInfo> CourseInfos = HttpContext.Session.Get <List <CourseInfo> >("CourseInfo"); CourseInfos.RemoveAll(c => c.SectionId == Section.Id); HttpContext.Session.Set <List <CourseInfo> >("CourseInfo", CourseInfos); Section = await _context.Section.FindAsync(id); if (Section != null) { DataAccessLayer.DataAccessClass dbAccess = new DataAccessLayer.DataAccessClass(); dbAccess.RemoveSection(Section); //_context.Section.Remove(Section); //await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, please 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(Assignment).State = EntityState.Modified; try { //await _context.SaveChangesAsync(); DataAccessLayer.DataAccessClass dbAccess = new DataAccessLayer.DataAccessClass(); dbAccess.UpdateAssignment(Assignment); } catch (DbUpdateConcurrencyException) { if (!AssignmentExists(Assignment.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { //Fills Days with list of checked days. Days = Request.Form["Days"].ToList(); //Initializes Section.Days to empty string. Section.Days = ""; //For each day in list, append to Section.Days. foreach (var x in Days) { Section.Days += x.ToString(); } if (!ModelState.IsValid) { return(Page()); } //_context.Attach(Section).State = EntityState.Modified; try { DataAccessLayer.DataAccessClass dbAccess = new DataAccessLayer.DataAccessClass(); dbAccess.UpdateSection(Section); //await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SectionExists(Section.Id)) { return(NotFound()); } else { throw; } } //add the new section to the session List <CourseInfo> CourseInfos = HttpContext.Session.Get <List <CourseInfo> >("CourseInfo"); CourseInfos.RemoveAll(c => c.SectionId == Section.Id); CourseInfo temp = new CourseInfo() { Course = _context.Course.FirstOrDefault(c => c.Id == Section.CourseId), SectionId = Section.Id, Notifications = _context.Notification.Where(n => n.Id == Section.CourseId).ToList(), Assignments = _context.Assignment.Where(a => a.Id == Section.CourseId).ToList() }; CourseInfos.Add(temp); HttpContext.Session.Set <List <CourseInfo> >("CourseInfo", CourseInfos); return(RedirectToPage("./Index")); }
// To protect from overposting attacks, please 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.Enrollment.Add(Enrollment); //await _context.SaveChangesAsync(); DataAccessLayer.DataAccessClass dbAccess = new DataAccessLayer.DataAccessClass(); dbAccess.AddEnrollment(Enrollment); return(RedirectToPage("./Index")); }
public void UpdateUploadTest() { int id = 38; int stid = 2; Submission submission = new Submission(); submission = _dataAccess._context.Submission.FirstOrDefault(s => s.Id == id & s.StudentAssignmentId == stid); SeeSharpLMS.DataAccessLayer.DataAccessClass data = new SeeSharpLMS.DataAccessLayer.DataAccessClass(); data.UpdateSubmission(submission); Assert.AreEqual(2, submission.StudentAssignmentId); Assert.AreEqual(null, submission.Link); Assert.AreEqual(DateTime.Now, submission.Date); Assert.AreEqual("You are genius!", submission.TextEntry); Assert.AreEqual("file.txt", submission.FilePath); }
public async Task <IActionResult> OnPostAsync(int?id) { user = HttpContext.Session.Get <ApplicationUser>("UserInfo"); Section = await _context.Section .Include(c => c.Course).FirstOrDefaultAsync(m => m.Id == id); Enrollment = new Enrollment(); Enrollment.SectionId = Section.Id; Enrollment.StudentId = user.Id; Charge = new Charge(); Charge.Reason = "Registration for " + Section.Course.Subject + " " + Section.Course.Number + " Section " + Section.Id; Charge.Date = DateTime.Now; Charge.Amount = Section.Course.CreditHours * SD.CostPerCredit + Section.Course.CourseFee; Charge.StudentId = user.Id; if (!ModelState.IsValid) { return(Page()); } //_context.Enrollment.Add(Enrollment); //await _context.SaveChangesAsync(); DataAccessLayer.DataAccessClass dbAccess = new DataAccessLayer.DataAccessClass(); dbAccess.AddEnrollment(Enrollment); dbAccess.AddCharge(Charge); //add new section to the session List <CourseInfo> CourseInfos = HttpContext.Session.Get <List <CourseInfo> >("CourseInfo"); //Course testCourse = _context.Section.Include(e => e.Course).FirstOrDefault(c => c.Id == Enrollment.SectionId).Course; CourseInfo temp = new CourseInfo() { Course = _context.Section.Include(e => e.Course).FirstOrDefault(c => c.Id == Enrollment.SectionId).Course, SectionId = Enrollment.SectionId, Notifications = new List <Notification>(_context.Notification.Where(n => n.SectionId == Enrollment.SectionId).ToList()), Assignments = new List <Assignment>(_context.Assignment.Where(a => a.SectionId == Enrollment.SectionId).ToList()) }; CourseInfos.Add(temp); HttpContext.Session.Set <List <CourseInfo> >("CourseInfo", CourseInfos); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Assignment = await _context.Assignment.FindAsync(id); if (Assignment != null) { //_context.Assignment.Remove(Assignment); //await _context.SaveChangesAsync(); DataAccessLayer.DataAccessClass dbAccess = new DataAccessLayer.DataAccessClass(); dbAccess.RemoveAssignment(Assignment); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Course = await _context.Course.FindAsync(id); if (Course != null) { //_context.Course.Remove(Course); //await _context.SaveChangesAsync(); DataAccessLayer.DataAccessClass dbAccess = new DataAccessLayer.DataAccessClass(); dbAccess.RemoveCourse(Course); } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { //Fills Days with list of checked days. Days = Request.Form["Days"].ToList(); //Initializes Section.Days to empty string. Section.Days = ""; //For each day in list, append to Section.Days. foreach (var x in Days) { Section.Days += x.ToString(); } if (!ModelState.IsValid) { return(Page()); } DataAccessLayer.DataAccessClass dbAccess = new DataAccessLayer.DataAccessClass(); dbAccess.AddSection(Section); //_context.Section.Add(Section); //await _context.SaveChangesAsync(); //add new section to the session List <CourseInfo> CourseInfos = HttpContext.Session.Get <List <CourseInfo> >("CourseInfo"); CourseInfo temp = new CourseInfo() { Course = _context.Course.FirstOrDefault(c => c.Id == Section.CourseId), SectionId = Section.Id, Notifications = new List <Notification>(), Assignments = new List <Assignment>() }; CourseInfos.Add(temp); HttpContext.Session.Set <List <CourseInfo> >("CourseInfo", CourseInfos); return(RedirectToPage("./Index")); }
[DataRow("Bad Data")] //TODO: Try to create a more generic data driven unit test, then replace Bad Data public void TestUpdateUserWithData(string id) { //TODO: notice the parameterized test. //the id i want to find (our student account) // primary key id // int id = 7;//display ID //************How do I grab a specific student using the ID assigend above************* user = _dataAccess._context.ApplicationUser.FirstOrDefault(u => u.Id == id); //instance of dataAccess Layer SeeSharpLMS.DataAccessLayer.DataAccessClass data = new SeeSharpLMS.DataAccessLayer.DataAccessClass(); //update user information with this stuff data.UpdateUser(user, "Jane1", "Deer", "*****@*****.**", "Hi, I am student!"); //compare what is supposed to be with user from database Assert.AreEqual("Jane1", user.FirstName); Assert.AreEqual("Deer", user.LastName); Assert.AreEqual("*****@*****.**", user.Email); Assert.AreEqual("Hi, I am student!", user.Description); }
public IActionResult OnPost(IFormFile file) { //var updateUser = _context.ApplicationUser.FirstOrDefault(x => x.Id == user.Id); var updateUser = _context.ApplicationUser.FirstOrDefault(u => u.Id == _userManager.GetUserId(User)); //updateUser.FirstName = Request.Form["EditFirstName"].ToString(); //updateUser.LastName = Request.Form["EditLastName"].ToString(); //updateUser.Email = Request.Form["EditEmail"].ToString(); //updateUser.UserName = Request.Form["EditEmail"].ToString(); //updateUser.NormalizedEmail = Request.Form["EditEmail"].ToString().ToUpper(); //updateUser.NormalizedUserName = Request.Form["EditEmail"].ToString().ToUpper(); //updateUser.Description = Request.Form["EditBio"].ToString(); //_context.SaveChanges(); ////var updateLink = new ProfileLink(); DataAccessLayer.DataAccessClass dbAccess = new DataAccessLayer.DataAccessClass(); dbAccess.UpdateUser(updateUser, Request.Form["EditFirstName"].ToString(), Request.Form["EditLastName"].ToString(), Request.Form["EditEmail"].ToString(), Request.Form["EditBio"].ToString()); Links = (_context.ProfileLink.Where(x => x.InstructorId == updateUser.Id)).ToList(); //If the user has any links, creates a new profile link object //then fills that object with a link from the list //and updates the links in the database //Upload the file if (file != null) { _unitOfWork.UploadImage(file); updateUser.ImagePath = file.FileName; } _context.SaveChanges(); if (Links.Count > 0) { //Creates the profile link object. var updateLink = new ProfileLink(); //For each link in the list, foreach (var x in Links) { //Fill the updatelink object with information from the list. updateLink = _context.ProfileLink.FirstOrDefault(l => l.Id == x.Id); //If the input that matches that link is empty the link is deleted. if (Request.Form[x.Id.ToString()].ToString().Length == 0) { _context.ProfileLink.Remove(updateLink); } //Else the link is updated with new information. else { updateLink.Link = Request.Form[x.Id.ToString()].ToString(); } //Save changes to the links. _context.SaveChanges(); } } //For each new link input field, adds new links to the database. for (int i = 0; i < 5; i++) { //Create new ProfileLink to add to database. var updateLink = new ProfileLink(); //If the input field is not empty, if (Request.Form["NewLinkId" + i].ToString().Length > 0) { //assigns the user's id to the InstructorId, updateLink.InstructorId = updateUser.Id; //adds the input field's information to the ProfileLink, updateLink.Link = Request.Form["NewLinkId" + i].ToString(); //and adds the new link to the datatable and saves the changes. _context.ProfileLink.Add(updateLink); _context.SaveChanges(); } } return(RedirectToPage("/Profile")); }