public async Task <IActionResult> Create([Bind("pricePuppyID,PricePuppyDesc,pricePuppy,pricePuppyImageUrl")] PricingPuppyModel pricingPuppyModel) { if (ModelState.IsValid) { _context.Add(pricingPuppyModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(pricingPuppyModel)); }
public async Task <IActionResult> Create([Bind("trainingServicesPriceID,trainingName,priceTraining,trainingDesc")] TrainingServicesPriceModel trainingServicesPriceModel) { if (ModelState.IsValid) { _context.Add(trainingServicesPriceModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(trainingServicesPriceModel)); }
public async Task <IActionResult> Create([Bind("TrainingId,DogName,TrainerId,GraduationDate,TrainingType")] TrainingDogModel trainingDogModel) { if (ModelState.IsValid) { _context.Add(trainingDogModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(trainingDogModel)); }
// GET: TrainersModels public async Task <IActionResult> Index() { // Get the trainers var trainersModel = await _context.TrainersModel.ToListAsync(); // Create an updatedTrainersModel array var updatedTrainersModel = new TrainersModel[trainersModel.Count]; int i = 0; // For each trainer in trainersModel foreach (TrainersModel trainer in trainersModel) { // Get all the dogs that have been trained by trainer.TrainerId var trainingDogCount = await _context.TrainingDogModel.CountAsync(m => m.TrainerId == trainer.TrainerId); // Set the training dog count to the trainer dog number trainer.DogNumber = trainingDogCount; // Set the updated trainer to the updatedTrainersModel updatedTrainersModel[i] = trainer; if (ModelState.IsValid) { try { _context.Update(trainer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } } i++; } return(View(updatedTrainersModel)); }
public async Task <IActionResult> UpdateAccount(string userId, string selectRole) { var user = await _context.IdentityUser.FindAsync(userId); if (user == null) { return(NotFound()); } _context.IdentityUser.Remove(user); await _context.SaveChangesAsync(); if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); } var role = _context.IdentityRole.FirstOrDefault(m => m.Name == selectRole); if (role == null) { return(NotFound()); } IdentityUserRole <string> newUserRole = new IdentityUserRole <string>(); newUserRole.UserId = userId; newUserRole.RoleId = role.Id; if (ModelState.IsValid) { _context.Add(newUserRole); await _context.SaveChangesAsync(); } return(RedirectToAction("ManageAccounts")); }
// GET: AddOneToTrainingServicesCart public async Task <IActionResult> AddOneToTrainingServicesCart(int?id) { // Code below copied from http://learningprogramming.net/net/asp-net-core-mvc/build-shopping-cart-with-session-in-asp-net-core-mvc/ // and updated it. // Get the training services cart List <CartItemModel> cart = SessionHelper.GetObjectFromJson <List <CartItemModel> >(HttpContext.Session, "trainingServicesCart"); // Check to see if the training service that was selected is in the training services cart int index = isExistTrainingService((int)id); // If the index is not equal -1 if (index != -1) { // Update the training services cart cartQty cart[index].CartQty++; // Get the cartItemModel where the training services price id is equal to the selected training service id var cartItemModel = await _context.CartItemModel .FirstOrDefaultAsync(m => m.TrainingServicesPriceID == id); // Check to see if the cart item model is null if (cartItemModel == null) { return(NotFound()); } // Update the cart item model cart quantity cartItemModel.CartQty++; // If the modelState is valid, update the cart item in the database //detail of model state //https://stackoverflow.com/questions/881281/what-is-modelstate-isvalid-valid-for-in-asp-net-mvc-in-nerddinner#targetText=ModelState.IsValid%20tells%20you%20if,validation%20system%20you're%20using. if (ModelState.IsValid) { try { _context.Update(cartItemModel); // Will update the cart table await _context.SaveChangesAsync(); // Save the changes } catch (DbUpdateConcurrencyException) { // If any errors, throw an exception throw; } } } SessionHelper.SetObjectAsJson(HttpContext.Session, "trainingServicesCart", cart); return(RedirectToAction("Index")); }