public async Task <IActionResult> Create([Bind("Name,Trainer")] Horse horse, int raceId, int laneId, int year) { ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User); Race race = await _context.Races.FindAsync(raceId, laneId, year); if (ModelState.IsValid) { Guid id = Guid.NewGuid(); horse.Id = id; horse.ApplicationUserId = user.Id; _context.Add(horse); try { race.HorseId = id; _context.Update(race); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HorseExists(horse.Id)) { return(NotFound()); } else { throw; } } await _context.SaveChangesAsync(); return(RedirectToAction("Race", "Races", new { raceNbr = raceId })); } return(View(horse)); }
public async Task <Unit> Handle(UpdateItemQuantityCommand request, CancellationToken cancellationToken) { if (request.Quantity < 0) { throw new ArgumentOutOfRangeException(); } var shoppingCartItem = await applicationDataContext.ShoppingCartItems .FirstOrDefaultAsync(sci => sci.Id == request.Id); if (shoppingCartItem == null) { throw new Exception(); } if (request.Quantity == 0) { applicationDataContext.ShoppingCartItems.Remove(shoppingCartItem); } else { shoppingCartItem.Quantity = request.Quantity; applicationDataContext.Update(shoppingCartItem); } await applicationDataContext.SaveChangesAsync(); return(Unit.Value); }
/// <summary> /// Replaces all properties of an entity /// </summary> /// <param name="entity"></param> /// <returns></returns> public virtual T Update(T entity) { if (entity == null) { throw new ArgumentNullException("entity"); } _context.Update(entity); _context.SaveChanges(); return(entity); }
public async Task <IActionResult> PayCash([FromBody] RouteValuesAmount amount) { ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User); //***CT***** Can convert to JSON -> Dictionary to avoid strongly type class //var json = JsonConvert.SerializeObject(amount); //var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(json); //int balance = Convert.ToInt32(dictionary.GetValueOrDefault("Amount")); //user.Balance += balance; user.Balance += amount.Amount; _context.Update(user); await _context.SaveChangesAsync(); return(Ok(user)); }
public Task UpdateAsync(T entity) { _dataContext.Update(entity); return(Task.CompletedTask); }
public void Update(Question question) { _context.Update(question); _context.SaveChanges(); }
public void Update(Quiz quiz) { _context.Update(quiz); _context.SaveChanges(); }