public async Task <IActionResult> PutSegment([FromRoute] int id, [FromBody] Segment segment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != segment.Id) { return(BadRequest()); } _context.Entry(segment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SegmentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Trip> > PostTrip(Trip trip) { _context.UserTrips.Add(trip); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTrip", new { id = trip.Id }, trip)); }
public async Task <IActionResult> Create([Bind("Id,Name,IsChecked,TodoId")] Item item) { if (ModelState.IsValid) { _context.Add(item); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(item)); }
public async Task <IActionResult> Post([FromBody] Trip value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } dbContext.Trips.Add(value); await dbContext.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Create([Bind("Id,SuppplierName,ConfirmationNumber,PickupName,PickupAddress,PickupSuburb,PickupCity,PickupRegion,PickupPostcode,PickupCountry,DropoffAddress,DropoffSuburb,DropoffCity,DropoffRegion,DropoffPostcode,DropoffCountry,PickupDate,PickupTime,DropoffDate,DropoffTime,SupplierPhoneNumber,TripId,DropoffCheckbox,Door,Seats,Transmisson,LargeBag,SmallBag,Litres")] CarRental carRental) { if (ModelState.IsValid) { _context.Add(carRental); await _context.SaveChangesAsync(); return(RedirectToAction("Details", new { carRental.Id })); } return(View(carRental)); }
public async Task <IActionResult> Create([Bind("Id,ConfirmationNumber,LodgingName,Address,AddressSuburb,AddressCity,AddressRegion,AddressPostcode,AddressCountry,ArrivalDate,ArrivalTime,DepartureDate,DepartureTime,NumOfGuests,NumOfRooms,RoomDescription,TripId")] Lodging lodging) { if (ModelState.IsValid) { _context.Add(lodging); await _context.SaveChangesAsync(); return(RedirectToAction("Details", new { lodging.Id })); } return(View(lodging)); }
public async Task <IActionResult> Create([Bind("Id,TypeOfTransport,CarrierName,ConfirmationNumber,DepartureAddress,DepartureSuburb,DepartureCity,DepartureRegion,DeparturePostcode,DepartureCountry,DepartureDate,DepartureTime,ArrivalDate,ArrivalTime,ArrivalAddress,ArrivalSuburb,ArrivalCity,ArrivalRegion,ArrivalPostcode,ArrivalCountry,TripId")] OtherTransportation otherTransportation) { if (ModelState.IsValid) { _context.Add(otherTransportation); await _context.SaveChangesAsync(); return(RedirectToAction("Details", new { otherTransportation.Id })); } return(View(otherTransportation)); }
public async Task <IActionResult> Create([Bind("Id,Title")] Todo todo) { if (ModelState.IsValid) { _context.Add(todo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(todo)); }
public async Task <IActionResult> Create([Bind("TripID,Country,City,Price,Duration,GuideID")] Trip trip) { if (ModelState.IsValid) { _context.Add(trip); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(trip)); }
public async Task <IActionResult> Create([Bind("Id,RestaurantName,Address,Suburb,City,Region,Postcode,Country,Description,Date,Time,Cuisine,NumberInParty,ConfirmationNumber,HoursOfOperation,DressCode,PriceRange,TripId")] Restaurant restaurant) { if (ModelState.IsValid) { _context.Add(restaurant); await _context.SaveChangesAsync(); return(RedirectToAction("Details", new { restaurant.Id })); } return(View(restaurant)); }
public async Task <IActionResult> Create([Bind("Id,TypeOfActivity,ConfirmationNumber,SupplierName,Description,StartDate,StartTime,EndDate,EndTime,Address,Suburb,City,Region,Postcode,Country,NumOfPeopleAttending,TripId")] ActivityTask activityTask) { if (ModelState.IsValid) { _context.Add(activityTask); await _context.SaveChangesAsync(); return(RedirectToAction("Details", new { activityTask.Id })); } return(View(activityTask)); }
public async Task <IActionResult> Create([Bind("Id,Name,DestinationCity,DestinationCountry,StartDate,FinishDate,Description")] Trip trip) { if (ModelState.IsValid) { _context.Add(trip); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(trip)); }
public async Task <IActionResult> PutAsync(int id, [FromBody] Trip value) { //_dbContext.Trips.Attach(value); 1) Older //_dbContext.Entry(value).State = EntityState.Modified; 2) Oldest /* * Writing it this way will avoid ChangeTracker by defining them directly in this void but if the Tracker is off... then why? * var tripFromDb = _dbContext.Trips.Find(id); * //LeftRight Comparison * tripFromDb.Name = value.Name; * tripFromDb.StartDate = value.StartDate; * _dbContext.SaveChanges(); */ //_dbContext.Trips.Update(value);Direct and UnClean to do. Use someting like that returns from _repo.Update(value); //EFCore1 Modern Way for a simple null and validation using the Required Class Attributes check //if (_dbContext.Trips.Find(id) == null)//Check for a Simple Null if (!_dbContext.Trips.Any(t => t.Id == id))//This blocks a null w/ a bool and what if they fire 2 queries instead of 1...? { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Save Async await _dbContext.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> PutAsync(int id, [FromBody] Models.Trip value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_context.Trips.Any(t => t.Id == id)) { return(NotFound()); } _context.Trips.Update(value); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> PutAsync(int id, [FromBody] Models.Trip value) { if (context.Trips.Any(t => t.Id == id)) { return(NotFound()); } context.Update(value); await context.SaveChangesAsync(); return(Ok()); }
// changed to Async because of the nature of the db calls public async Task <IActionResult> PutAsync(int id, [FromBody] Trip values) { // validate Id if (!_context.Trips.Any(t => t.Id == id)) // SELECT TOP(1) on the Db { return(NotFound(id)); } // validate state if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // we also need to worry about nulls // new way, updates the entire object _context.Trips.Update(values); await _context.SaveChangesAsync(); // if not bad, return okay (200) return(Ok()); }
public async Task <IActionResult> PutTrip(TripModel m) { var t = await _DB.Trips.FindAsync(m.Id); if (t == null) { return(NotFound()); } if (!CanEditOrDelete(_User.UserId, m.UserId)) { return(NotFound()); //for internal should be NotAuthorized, but for public security reasons we should return zero info about request. } //update entry t.DateUTC = m.DateUTC; t.Destination = m.Destination; t.Country = m.Country; t.Title = m.Title; t.UserId = m.UserId; _DB.Entry(t).State = EntityState.Modified; try { await _DB.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TripExists(m.Id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutAsync(int id, [FromBody] Trip tripToUpdate) { if (_context.Trips.Find(id) == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Trips.Update(tripToUpdate); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> PutAsync(int id, [FromBody] Trip trip) { if (!_context.Trips.Any(t => t.Id == id)) // tests if there is any trip with the id passed as parameter if not return not found { return(NotFound()); } if (!ModelState.IsValid) //if state of model is NOT valid return bad request { return(BadRequest(ModelState)); } _context.Trips.Update(trip); // if state valid and trip found, update with the modified trip await _context.SaveChangesAsync(); //waits for the update to finish return(Ok()); }
public async Task <IActionResult> PutAsync(int id, [FromBody] Trip value) { if (!_context.Trips.Any(t => t.Id == id)) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //When The Object Is Tracked We Can Use A Shorthand _context.Trips.Update(value); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> PutAsync(int id, [FromBody] Models.Trip value) { //var tripFromDb = _context.Trips.Find(id); //tripFromDb.Name = value.Name; //tripFromDb.StartDate = value.StartDate; if (!_context.Trips.Any(t => t.Id == id)) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Trips.Update(value); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> PutAsync(int id, [FromBody] Trip value) { // we can make the validation as: //if (_context.Trips.Find(id) == null) // But this will be heaver for the DB than what we want it to be //instead if (!_context.Trips.Any(t => t.Id == id)) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Trips.Update(value); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> PutAsync(int id, [FromBody] Trip value) { // .Any returns a Boolean. .Find() returns the whole object. Lighter on the db query if (!_dbcontext.Trips.Any(t => t.Id == id)) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // this Update() method uploads and updates ALL the values in the object, even if there is // only one change in one column // what about nulls? _dbcontext.Trips.Update(value); await _dbcontext.SaveChangesAsync(); return(Ok()); }
public async Task Add(Trip trip) { _context.Trips.Add(trip); await _context.SaveChangesAsync(); }
public async void AddTrip(Trip trip) { context.Trips.Add(trip); await context.SaveChangesAsync(); }