public async Task <IActionResult> PostCarPoolingModel([FromBody] CarPoolingModel carPoolingModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.CarPooling.Add(carPoolingModel); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (CarPoolingModelExists(carPoolingModel.id)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetCarPoolingModel", new { id = carPoolingModel.id }, carPoolingModel)); }
public async Task <IActionResult> PutCarPoolingModel([FromRoute] int id, [FromBody] CarPoolingModel carPoolingModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != carPoolingModel.id) { return(BadRequest()); } carPoolingModel.TimeStamp = DateTime.Now; _context.Entry(carPoolingModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarPoolingModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(int id, [Bind("id,From,Name,PhoneNumber,Time,TimeStamp,To,UID")] CarPoolingModel carPoolingModel) { if (id != carPoolingModel.id) { return(NotFound()); } if (ModelState.IsValid) { try { carPoolingModel.TimeStamp = DateTime.Now; _context.Update(carPoolingModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarPoolingModelExists(carPoolingModel.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(carPoolingModel)); }
public async Task <IActionResult> Create(CarPoolingModel carPoolingModel) { if (ModelState.IsValid) { carPoolingModel.TimeStamp = DateTime.Now; _context.Add(carPoolingModel); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(carPoolingModel)); }
public async Task <IActionResult> GetCarPoolingModel([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } CarPoolingModel carPoolingModel = await _context.CarPooling.SingleOrDefaultAsync(m => m.id == id); if (carPoolingModel == null) { return(NotFound()); } return(Ok(carPoolingModel)); }