public async Task <IActionResult> Edit(int id, [Bind("InventoryId,Stock,Price,ProductId,PlatformId")] Inventory inventory) { if (id != inventory.InventoryId) { return(NotFound()); } ModelState.Remove("PlatformId"); ModelState.Remove("ProductId"); if (ModelState.IsValid && await InventoriesService.ValidEditAsync(inventory, _db)) { try { _db.Update(inventory); await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InventoryExists(inventory.InventoryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["PlatformId"] = new SelectList(_db.GamePlatform, "PlatformId", "PlatformName", inventory.PlatformId); ViewData["ProductId"] = new SelectList(_db.Product, "ProductId", "Name", inventory.ProductId); ModelState.AddModelError("", "Something went wrong"); return(View(inventory)); }
public async Task <IActionResult> Put(int id, [FromBody] User userUpdateValue) { try { userUpdateValue.EntryTime = DateTime.Now; var userToEdit = await _context.User .AsNoTracking() .SingleOrDefaultAsync(m => m.ID == id); if (userToEdit == null) { return(NotFound("Could not update user as it was not Found")); } else { _context.Update(userUpdateValue); await _context.SaveChangesAsync(); return(Ok("Updated user - " + userUpdateValue.Name)); } } catch (DbUpdateException) { //Log the error (uncomment ex variable name and write a log.) ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); return(NotFound("User not Found")); } }
public async Task <IActionResult> Edit(int id, [Bind("IngredientId,Name,Price")] Ingredient ingredient) { if (id != ingredient.IngredientId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(ingredient); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!IngredientExists(ingredient.IngredientId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(ingredient)); }
public async Task <IActionResult> Edit(int id, [Bind("PublisherId,PublisherName")] Publisher publisher) { if (id != publisher.PublisherId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(publisher); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PublisherExists(publisher.PublisherId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(publisher)); }
public async Task <IActionResult> Edit(int id, [Bind("GameTypeId,GenreName")] GameType gameType) { if (id != gameType.GameTypeId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(gameType); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GameTypeExists(gameType.GameTypeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(gameType)); }
public async Task <IActionResult> Edit(int id, [Bind("CategoryId,Name,Active")] Category category) { if (id != category.CategoryId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(category.CategoryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Edit(int id, [Bind("FeatureId,Feature,ProductId")] ProductFeature productFeature) { if (id != productFeature.FeatureId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(productFeature); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductFeatureExists(productFeature.FeatureId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "Name", productFeature.ProductId); return(View(productFeature)); }
public async Task <IActionResult> Edit(int id, [Bind("PGRatingId,Rating")] PGRating pGRating) { if (id != pGRating.PGRatingId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(pGRating); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PGRatingExists(pGRating.PGRatingId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(pGRating)); }
public static bool ChangePassword(ClaimsPrincipal user, string password, WebshopDbContext db) { string guidString = user.Claims.Where(claim => claim.Type == ClaimTypes.Sid).Select(s => s.Value).SingleOrDefault(); if (!Guid.TryParse(guidString, out Guid userId)) { return(false); } User u = UserService.GetUser(userId, db); u.Password = Hashing.HashPassword(password); db.Update(u); db.SaveChanges(); return(true); }
public static bool ChangeAddress(ClaimsPrincipal user, ChangeAddressViewModel addressViewModel, WebshopDbContext db) { string guidString = user.Claims.Where(claim => claim.Type == ClaimTypes.Sid).Select(s => s.Value).SingleOrDefault(); if (!Guid.TryParse(guidString, out Guid userId)) { return(false); } User u = UserService.GetUser(userId, db); u.Street = addressViewModel.Street; u.PostalCode = addressViewModel.PostalCode; db.Update(u); db.SaveChanges(); return(true); }
public async Task UpdateDishAsync(Dish dish, List <DishIngredient> dishIngredients = null) { _context.Update(dish); await _context.SaveChangesAsync(); if (dishIngredients != null) { //remove old DishIngredients List <DishIngredient> oldDishIngredients = _context.DishIngredients.Where(di => di.DishId == dish.DishId).ToList(); _context.DishIngredients.RemoveRange(oldDishIngredients); await _context.SaveChangesAsync(); //add new DishIngredients _context.DishIngredients.AddRange(dishIngredients); await _context.SaveChangesAsync(); } }