public async Task <IActionResult> Put(TripEditModel tripEdit) { var response = new Response(); var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var existsTrip = this.tripsService.Exists(x => x.Id == tripEdit.TripId && x.ApplicationUserId == userId); if (!existsTrip) { response.Message = "No such trip!"; return(this.NotFound(response)); } var existsCity = this.citiesService.Exists(x => x.Id == tripEdit.CityId); var existsCrag = this.cragsService.Exists(x => x.Id == tripEdit.CragId); var existsSector = this.sectorsService.Exists(x => x.Id == tripEdit.SectorId && x.CragId == tripEdit.CragId); if (tripEdit.SectorId == null) { existsSector = true; } if (!this.ModelState.IsValid || tripEdit.Leaving > tripEdit.Returning) { response.Message = "Invalid input!"; return(this.BadRequest(response)); } if (!existsCity) { response.Message = "No such city!"; return(this.NotFound(response)); } if (!existsCrag) { response.Message = "No such crag!"; return(this.NotFound(response)); } if (!existsSector) { response.Message = "No such sector!"; return(this.NotFound(response)); } await this.tripsService.EditAsync(tripEdit); response.Message = "Successfully edited trip!"; return(this.Ok(response)); }
public async Task EditAsync(TripEditModel tripEdit) { var original = this.tripsRepository .All() .First(x => x.Id == tripEdit.TripId); original.CityId = tripEdit.CityId; original.CragId = tripEdit.CragId; original.SectorId = tripEdit.SectorId; original.Leaving = tripEdit.Leaving; original.Returning = tripEdit.Returning; original.Comment = tripEdit.Comment; original.Seats = tripEdit.Seats; original.WithCar = tripEdit.WithCar; await this.tripsRepository.SaveChangesAsync(); }