public async Task <IActionResult> PutUserData(User user) { int id = _userService.GetAuthorizedUserId(this.User); if (id != user.Id) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutLiveTour(int id, LiveTour liveTour) { int idAgency = await _userService.GetAuthorizedAgencyId(this.User); if (id != liveTour.Id) { return(BadRequest()); } if (liveTour.AgencyID != idAgency) { return(BadRequest(new { message = "resource is not yours" })); } _context.Entry(liveTour).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LiveTourExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutBaseTour(int id, BaseTour baseTour) { int idAgency = await _userService.GetAuthorizedAgencyId(this.User); if (id != baseTour.Id) { return(BadRequest()); } //var oldBaseTour = await _context.BaseTours.Where(b => b.AgencyID == idAgency && b.Id == id).FirstOrDefaultAsync(); if (baseTour.AgencyID != idAgency) { return(BadRequest(new { message = "resource is not yours" })); } _context.Entry(baseTour).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BaseTourExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Agency> > GetAgency() { int idAgency = await _userService.GetAuthorizedAgencyId(this.User); var agency = await _context.Agencies.FindAsync(idAgency); _context.Entry(agency).Collection(a => a.Users).Load(); if (agency == null) { return(NotFound()); } return(agency); }
public async Task <ActionResult <BaseTour> > GetBaseTour(int id) { var baseTour = await _context.BaseTours.FindAsync(id); if (baseTour == null) { return(NotFound()); } _context.Entry(baseTour).Collection(b => b.BaseTourZones).Load(); return(baseTour); }