// To protect from overposting attacks, enable the specific properties you want to bind to, for public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } // display the available select list items var emptyPtSession = new TrainingRoutine(); displayPersonalTrainingNames = await _context.PersonalTrainingSessions.ToListAsync(); var entry = _context.Add(emptyPtSession); // this is the line that can manually set values of the pt name, searches the products, when the prod id == the index assigned, we get the first item, thats a title, and convert to string // this bascially gets the ID number of what is selected from the select list on personal training. TrainingRoutineVM.RoutineName = displayPersonalTrainingNames.Where(a => a.PersonalTrainingID == getIndexOfPt).FirstOrDefault().PersonalTrainingName.ToString(); TrainingRoutineVM.PersonalTrainingID = displayPersonalTrainingNames.Where(a => a.PersonalTrainingID == getIndexOfPt).FirstOrDefault().PersonalTrainingID; entry.CurrentValues.SetValues(TrainingRoutineVM); await _context.SaveChangesAsync(); PopulateProductDropDownList(_context, emptyPtSession.PersonalTrainingSession.PersonalTrainingName); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var user = await _userManager.GetUserAsync(HttpContext.User); if (user == null) { return(RedirectToPage("/Account/Manage/Login")); } var emptyPtSession = new PersonalTraining(); // display the available select list items displayProductTitles = await _context.Products.ToListAsync(); var entry = _context.Add(emptyPtSession); // this is the line that can manually set values of the pt name, searches the products, when the prod id == the index assigned, we get the first item, thats a title, and convert to string PersonalTrainingVM.PersonalTrainingName = displayProductTitles.Where(a => a.ProductID == getIndexOfTitleList).FirstOrDefault().Title.ToString(); // add product picture if (Request.Form.Files.Count > 0) { IFormFile file = Request.Form.Files.FirstOrDefault(); using (var dataStream = new MemoryStream()) { await file.CopyToAsync(dataStream); PersonalTrainingVM.PtProductPicture = dataStream.ToArray(); } } entry.CurrentValues.SetValues(PersonalTrainingVM); await _context.SaveChangesAsync(); PopulateProductDropDownList(_context, emptyPtSession.ProductID); 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()); } var user = await _userManager.GetUserAsync(HttpContext.User); if (user == null) { return(RedirectToPage("/Account/Manage/Login")); } var emptySupplement = new Supplement(); // display the available select list items displayProductTitles = await _context.Products.ToListAsync(); var entry = _context.Add(emptySupplement); // add product picture if (Request.Form.Files.Count > 0) { IFormFile file = Request.Form.Files.FirstOrDefault(); using (var dataStream = new MemoryStream()) { await file.CopyToAsync(dataStream); SupplementVM.SupplementPicture = dataStream.ToArray(); } } entry.CurrentValues.SetValues(SupplementVM); await _context.SaveChangesAsync(); PopulateProductDropDownList(_context, emptySupplement.ProductID); return(RedirectToPage("./Index")); }