public async Task <IActionResult> OnPostAdd(int id, int classID) { try { Class2 = await _context.Class .FirstOrDefaultAsync(m => m.ClassID == classID); Class2.Capacity--; StudentClass StudentClass = new StudentClass(); StudentClass.StudentID = id; StudentClass.ClassID = classID; _context.Class.Update(Class2); _context.StudentClass.Add(StudentClass); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(Student.StudentID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./ChangeSchedule", new { id })); }
// 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() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } if (!ModelState.IsValid) { return(Page()); } var Userid = _signInManager.Context.User.Claims.FirstOrDefault().Value; var emptyAdress = new Address(); AddressVM.OwnerId = Userid; AddressVM.Owner = user; AddressVM.Name = Input.Name; AddressVM.AddressLine = Input.AddressLine; /*if (await TryUpdateModelAsync<Address>( * emptyAdress, * "address", // Prefix for form value. * a => a.Name, a => a.AddressLine)) * {*/ var entry = _context.Add(new Address()); entry.CurrentValues.SetValues(AddressVM); await _context.SaveChangesAsync(); return(RedirectToPage("./AddressIndex")); //} }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Assessment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AssessmentExists(Assessment.AssessmentId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index", new { id = Assessment.ClassID })); }
// 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(zkeeper).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!zkeeperExists(zkeeper.ZKid)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var dailyStatistics = _context.DailyStatistics.Find(DailyStatistic.Id); _context.Entry(dailyStatistics).CurrentValues.SetValues(DailyStatistic); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DailyStatisticExists(DailyStatistic.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } var address = await _context.Addresses.FindAsync(id); if (address == null) { return(NotFound()); } try { _context.Addresses.Remove(address); await _context.SaveChangesAsync(); return(RedirectToPage("./AddressIndex")); } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log.) return(RedirectToAction("./Delete", new { id, saveChangesError = true })); } }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var files = HttpContext.Request.Form.Files; if (files.Count > 0) { byte[] pic = null; using (var fs = files[0].OpenReadStream()) { using (var ms = new MemoryStream()) { fs.CopyTo(ms); pic = ms.ToArray(); } } Student.Picture = pic; } _context.Student.Add(Student); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { _context.Class.Add(Class); await _context.SaveChangesAsync(); //goes in and finds the last record in the table so we can use the id to create our two class schedule records int classID = _context.Class .OrderByDescending(c => c.ClassID) .Select(r => r.ClassID) .First(); ScheduleFirstDay.ClassID = classID; ScheduleSecondDay.ClassID = classID; _context.ClassSchedule.Add(ScheduleFirstDay); _context.ClassSchedule.Add(ScheduleSecondDay); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Note.Add(Note); await _context.SaveChangesAsync(); return(RedirectToPage("./Index", new { id = Note.StudentID })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.DailyStatistics.Add(DailyStatistic); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Assessment.Add(Assessment); await _context.SaveChangesAsync(); return(RedirectToPage("./Index", new { id = Assessment.ClassID })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.StudentPublicSchoolClass.Add(StudentPublicSchoolClass); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int id) { var addressToUpdate = await _context.Addresses.FindAsync(id); if (addressToUpdate == null) { return(NotFound()); } var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound()); } // Address.Name = Input.Name; // Address.AddressLine = Input.AddressLine; var Userid = _signInManager.Context.User.Claims.FirstOrDefault().Value; addressToUpdate.OwnerId = Userid; addressToUpdate.Owner = user; if (addressToUpdate.Name != Input.Name) { addressToUpdate.Name = Input.Name; } if (addressToUpdate.AddressLine != Input.AddressLine) { addressToUpdate.AddressLine = Input.AddressLine; } //AddressVM.OwnerId = Userid; //AddressVM.Owner = user; //AddressVM.Name = Input.Name; //AddressVM.AddressLine = Input.AddressLine; //entry.CurrentValues.SetValues(AddressVM); var entry = _context.Addresses.Update(addressToUpdate); entry.CurrentValues.SetValues(addressToUpdate); await _context.SaveChangesAsync(); return(RedirectToPage("./AddressIndex")); }
public async Task <IActionResult> OnPostAsync(int id) { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Class).State = EntityState.Modified; var ClassSchedules = _context.ClassSchedule.Where(c => c.ClassID == id); _context.ClassSchedule.RemoveRange(ClassSchedules); await _context.SaveChangesAsync(); try { ScheduleFirstDay.ClassID = id; ScheduleSecondDay.ClassID = id; _context.ClassSchedule.Add(ScheduleFirstDay); _context.ClassSchedule.Add(ScheduleSecondDay); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClassExists(Class.ClassID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Note = await _context.Note.FindAsync(id); if (Note != null) { _context.Note.Remove(Note); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index", new { id = Note.StudentID })); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Inventory = await _context.Inventory.FindAsync(id); if (Inventory != null) { _context.Inventory.Remove(Inventory); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Student = await _context.Student.FindAsync(id); if (Student != null) { _context.Student.Remove(Student); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } zkeeper = await _context.zkeeper.FindAsync(id); if (zkeeper != null) { _context.zkeeper.Remove(zkeeper); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Assessment = await _context.Assessment.FindAsync(id); if (Assessment != null) { _context.Assessment.Remove(Assessment); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index", new { id = Assessment.ClassID })); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } DailyStatistic = await _context.DailyStatistics.FindAsync(id); if (DailyStatistic != null) { _context.DailyStatistics.Remove(DailyStatistic); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task OnPostAsync() { List <StudentAssessment> FromDB = await _context.StudentAssessment .Include(s => s.Assessment) .Include(s => s.Student) .Where(a => a.AssessmentID == StudentAssessment[0].AssessmentID).ToListAsync(); for (int i = 0; i < FromDB.Count; i++) { FromDB[i].StudentID = StudentAssessment[i].StudentID; FromDB[i].PointsAwarded = StudentAssessment[i].PointsAwarded; FromDB[i].AssessmentID = StudentAssessment[i].AssessmentID; FromDB[i].Comment = StudentAssessment[i].Comment; } await _context.SaveChangesAsync(); await OnGetAsync(StudentAssessment[0].AssessmentID); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var files = HttpContext.Request.Form.Files; if (files.Count > 0) { byte[] pic = null; using (var fs = files[0].OpenReadStream()) { using (var ms = new MemoryStream()) { fs.CopyTo(ms); pic = ms.ToArray(); } } Student.Picture = pic; } _context.Attach(Student).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(Student.StudentID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Class = await _context.Class.FindAsync(id); var ClassSchedules = _context.ClassSchedule.Where(c => c.ClassID == id); if (Class != null) { _context.Class.Remove(Class); _context.ClassSchedule.RemoveRange(ClassSchedules); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task OnGetAsync(int studentId, int classId) { StudentAssessment = await _context.StudentAssessment .Include(s => s.Student) .Where(s => s.StudentID == studentId) .Where(s => s.Assessment.ClassID == classId) .ToListAsync(); IList <Assessment> assessments = await _context.Assessment .Where(c => c.ClassID == classId) .ToListAsync(); int i = 0; //Add grades into database if not already there while (StudentAssessment.Count != assessments.Count) { StudentAssessment sa = await _context.StudentAssessment .Where(s => s.StudentID == studentId) .Where(a => a.AssessmentID == assessments[i].AssessmentId) .FirstOrDefaultAsync(); if (sa == null) { sa = new StudentAssessment { AssessmentID = assessments[i].AssessmentId, StudentID = studentId, Comment = "" }; _context.StudentAssessment.Add(sa); await _context.SaveChangesAsync(); } i++; StudentAssessment = await _context.StudentAssessment .Include(s => s.Student) .Where(s => s.StudentID == studentId) .Where(s => s.Assessment.ClassID == classId) .ToListAsync(); } }
public async Task <IActionResult> OnPostAsync(string email, string firstname, string lastname, int?PointsSpend) { var id = _userManager.GetUserId(User); ApplicationUser gebruiker = await _userManager.GetUserAsync(User); // Select an new highest TMPID. int currentTMPID = 0; bool UniqueTMPCheck = true; Random rnd = new Random(); while (UniqueTMPCheck) { currentTMPID = rnd.Next(1, 2000000000); UniqueTMPCheck = _context.Key.Any(item => item.TMPID == currentTMPID); } mehdiid = id; if (User.Identity.IsAuthenticated) { var fullcart = (from cartprd in _context.Shopping_Card_Products from cartid in _context.Shopping_card where cartprd.Shopping_card_ID == cartid.ID && cartid.User_ID == id select cartprd); //proptabtab = fullcart.ToList(); var query = from shopping in _context.Shopping_card where shopping.User_ID == id let shoppingProducts = ( from shoppingProdutstable in _context.Shopping_Card_Products from Products in _context.Product where shoppingProdutstable.Shopping_card_ID == shopping.ID && shoppingProdutstable.Product_ID == Products.ID select new ResponseShopingCart() { product = Products, quantity = shoppingProdutstable.quantity + 1 } ).ToList() select shoppingProducts; proptabtab = query.FirstOrDefault(); if (PointsSpend > gebruiker.TPunten || PointsSpend == null) { PointsSpend = 0; } Order Order = new Order() { User_ID = id, PointsGain = 0, Paid = 0, PointsSpend = (int)PointsSpend, OrderDate = DateTime.Now, Keys = new List <Key>(), }; float TotalPrice = 0; foreach (var item in proptabtab) { int i = 0; while (i < item.quantity) { TotalPrice = TotalPrice + item.product.PriceFinal; Order.Keys.Add(new Key() { UserID = id, TMPID = currentTMPID, License = Guid.NewGuid().ToString(), ProductID = item.product.ID, Price = item.product.PriceFinal, OrderDate = DateTime.Now }); i = i + 1; } } if (PointsSpend != null && PointsSpend != 0) { double Discount = Math.Round((Math.Pow(((int)PointsSpend + TotalPrice), 1.8) / 1000) * 100) / 100; TotalPrice = (float)Math.Round((TotalPrice - Discount) * 100) / 100; } Order.PointsGain = (int)Math.Round(TotalPrice); Order.Paid = TotalPrice; gebruiker.TPunten = gebruiker.TPunten + (int)Math.Round(TotalPrice) - (int)PointsSpend; _context.Users.Update(gebruiker); _context.Order.Add(Order); // From List keys to only key array EmailKeyArray[] EmailKey = new EmailKeyArray[Order.Keys.Count]; for (int j = 0; j < Order.Keys.Count; j++) { EmailKey[j] = new EmailKeyArray(); EmailKey[j].Key = Order.Keys[j].License; EmailKey[j].ProductName = (from p in _context.Product where p.ID == Order.Keys[j].ProductID select p.ResponseName).FirstOrDefault(); } // Send the E-mail _emailSender.SendKeysToEmailAsync(email, EmailKey, firstname, lastname); _context.Shopping_Card_Products.RemoveRange(fullcart); } else // Voor cookie shoppingCard { string cookieshoping = Request.Cookies["ShoppingCart"]; List <shoppingCart_cookie> shoppingcartlist = Cookie.Cookiereader_shoppingcart(cookieshoping); List <Key> keys = new List <Key>(); Order Order = new Order() { PointsGain = 0, Paid = 0, PointsSpend = 0, OrderDate = DateTime.Now, Keys = new List <Key>(), }; float TotalPrice = 0; foreach (shoppingCart_cookie item in shoppingcartlist) { int i = 0; while (i < item.Quantity) { TotalPrice = TotalPrice + _context.Product.Where(x => x.ID == item.ProductID).Select(x => x.PriceFinal).FirstOrDefault(); Order.Keys.Add(new Key() { TMPID = currentTMPID, License = Guid.NewGuid().ToString(), ProductID = item.ProductID, Price = _context.Product.Where(x => x.ID == item.ProductID).Select(x => x.PriceFinal).FirstOrDefault(), OrderDate = DateTime.Now }); i = i + 1; } } Order.Paid = TotalPrice; _context.Order.Add(Order); // From List keys to only key array EmailKeyArray[] EmailKey = new EmailKeyArray[Order.Keys.Count]; for (int j = 0; j < Order.Keys.Count; j++) { EmailKey[j] = new EmailKeyArray(); EmailKey[j].Key = Order.Keys[j].License; EmailKey[j].ProductName = (from p in _context.Product where p.ID == Order.Keys[j].ProductID select p.ResponseName).FirstOrDefault(); } // Send the E-mail _emailSender.SendKeysToEmailAsync(email, EmailKey, firstname, lastname); // Cookie instellingen. CookieOptions cookieOptions = new CookieOptions { Expires = DateTime.Now.AddDays(14), HttpOnly = true }; // Split characters: // - between productID and quantity // + between Produts in shopping card. // Tuple<ProductID, Quantity Response.Cookies.Append("ShoppingCart", "", cookieOptions); } if (!ModelState.IsValid) { return(Page()); } await _context.SaveChangesAsync(); return(Redirect("FinishCheckout?id=" + currentTMPID)); }
public async Task OnPostImport(IFormFile postedFile) { if (postedFile != null) { using (ExcelPackage package = new ExcelPackage(postedFile.OpenReadStream())) { ExcelWorksheet worksheet = package.Workbook.Worksheets[0]; int colCount = worksheet.Dimension.End.Column; //get Column Count int rowCount = worksheet.Dimension.End.Row; //get row count bool endOfFile = false; for (int row = 6; row <= rowCount; row++) { int StudentID = 0; DateTime Date = new DateTime(); DateTime TimeIn = new DateTime(); string CourseName = ""; int AttendanceStatusID = 1; Models.Attendance tempAttendance = new Models.Attendance(); for (int col = 1; col <= colCount; col++) { //string currentThing = " Row:" + row + " column:" + col + " Value:" + worksheet.Cells[row, col].Value?.ToString().Trim(); if (col == 1) { if (worksheet.Cells[row, col].Value == null) { endOfFile = true; break; } StudentID = Int32.Parse(worksheet.Cells[row, col].Value?.ToString().Trim()); } else if (col == 3) { CourseName = worksheet.Cells[row, col].Value?.ToString().Trim(); } else if (col == 4) { Date = DateTime.Parse(worksheet.Cells[row, col].Value?.ToString().Trim()); } else if (col == 6) { string tempDate = worksheet.Cells[row, col].Value?.ToString().Trim(); if (tempDate == "Missed") { AttendanceStatusID = 3; } else { TimeIn = Convert.ToDateTime(tempDate); AttendanceStatusID = 1; } } } if (!endOfFile) { tempAttendance.StudentID = StudentID; tempAttendance.Date = Date; tempAttendance.CourseName = CourseName; if (AttendanceStatusID == 1) { tempAttendance.TimeIn = TimeIn; } tempAttendance.AttendanceStatusID = AttendanceStatusID; try { _context.Attendance.Add(tempAttendance); await _context.SaveChangesAsync(); } catch (DbUpdateException) { errorMessage = true; } } } } } var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); string userId = claim.Value; Course = await _context.Course .ToListAsync(); Class = await _context.Class.Include(c => c.Course).Include(c => c.Term).Where(u => u.ClassID == -1).ToListAsync(); IList <ClassInstructor> Classes = await _context.ClassInstructor .Include(c => c.Class) .Where(u => u.UserID == userId) .ToListAsync(); //Class = new IList<Class>(); for (int i = 0; i < Classes.Count; i++) { Class.Add(await _context.Class .Include(c => c.Course) .Include(c => c.Term) .Where(c => c.ClassID == Classes[i].ClassID).FirstOrDefaultAsync()); } //get the last entered attendance for classes LastEnteredAttendance = await _context.Attendance .OrderByDescending(d => d.Date) .GroupBy(c => c.CourseName) .Select(c => c.First()) .ToListAsync(); }
public async Task <IActionResult> OnPostAsync(string email, string firstname, string lastname, int?PointsSpend, int productid) { var id = _userManager.GetUserId(User); ApplicationUser gebruiker = await _userManager.GetUserAsync(User); // Select an new highest TMPID. int currentTMPID = 0; bool UniqueTMPCheck = true; Random rnd = new Random(); while (UniqueTMPCheck) { currentTMPID = rnd.Next(1, 2000000000); UniqueTMPCheck = _context.Key.Any(item => item.TMPID == currentTMPID); } if (PointsSpend > gebruiker.TPunten || PointsSpend == null) { PointsSpend = 0; } if (gebruiker.TPunten < 250) { return(RedirectToPage()); } else { Order Order = new Order() { User_ID = id, PointsGain = 0, Paid = 0, PointsSpend = (int)PointsSpend, OrderDate = DateTime.Now, Keys = new List <Key>(), }; if (productid != 0) { Order.Keys.Add(new Key() { UserID = id, TMPID = currentTMPID, License = Guid.NewGuid().ToString(), ProductID = productid, Price = 0, OrderDate = DateTime.Now }); PointsSpend = PointsSpend + (int)250; Order.PointsSpend = (int)PointsSpend; } gebruiker.TPunten = gebruiker.TPunten - (int)PointsSpend; _context.Users.Update(gebruiker); _context.Order.Add(Order); } // From List keys to only key array //EmailKeyArray[] EmailKey = new EmailKeyArray[Order.Keys.Count]; //for (int j = 0; j < Order.Keys.Count; j++) //{ // EmailKey[j] = new EmailKeyArray(); // EmailKey[j].Key = Order.Keys[j].License; // EmailKey[j].ProductName = (from p in _context.Product // where p.ID == Order.Keys[j].ProductID // select p.ResponseName).FirstOrDefault(); //} await _context.SaveChangesAsync(); return(Redirect("FinishCheckout?id=" + currentTMPID)); }