public async Task <IActionResult> PutVehicle([FromRoute] long id, [FromBody] Vehicle vehicle) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != vehicle.Id) { return(BadRequest()); } SetDiscounts(vehicle); _context.Vehicles.Update(vehicle); _context.Entry(vehicle).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VehicleExists(id)) { return(NotFound()); } else { throw; } } return(Ok(vehicle)); }
public async Task <IActionResult> PutDiscount([FromRoute] long id, [FromBody] Discount discount) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != discount.DiscountId) { return(BadRequest()); } _context.Entry(discount).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DiscountExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutDriver([FromRoute] long id, [FromBody] Driver driver) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != driver.Id) { return(BadRequest()); } SetDiscounts(driver); _context.Drivers.Update(driver); _context.Entry(driver).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DriverExists(id)) { return(NotFound()); } else { throw; } } return(Ok(driver)); }
public async Task <IActionResult> UpdateAgentStatusAll([FromBody] Dictionary <string, AccountStatus> agentStatus) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var users = _context.Users; ApplicationUser user; foreach (var status in agentStatus) // key: AgentID, value: Enabled or Disabled { user = users.Where(u => u.Id == status.Key).SingleOrDefault(); if (user != null) { user.AccountStatus = status.Value; _context.Entry(user).State = EntityState.Modified; } } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { foreach (var status in agentStatus) { if (!UserExists(status.Key)) { return(NotFound()); } else { throw; } } } return(NoContent()); }