public async Task <IActionResult> Create(DipEntity dipEntity) { if (ModelState.IsValid) { dipEntity.Plaque = dipEntity.Plaque.ToUpper(); _context.Add(dipEntity); /****************************entrecachado para evento***************/ try { await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, ("la placa ya existe")); } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); } } /***************************fin********************************/ } return(View(dipEntity)); }
public DipResponse ToDipResponse(DipEntity DipEntity) { return(new DipResponse { Id = DipEntity.Id, Plaque = DipEntity.Plaque, Trips = DipEntity.Trips?.Select(t => new TripResponse { EndDate = t.EndDate, Id = t.Id, Qualification = t.Qualification, Remarks = t.Remarks, Source = t.Source, SourceLatitude = t.SourceLatitude, SourceLongitude = t.SourceLongitude, StartDate = t.StartDate, Target = t.Target, TargetLatitude = t.TargetLatitude, TargetLongitude = t.TargetLongitude, TripDetails = t.TripDetails?.Select(td => new TripDetailResponse { Date = td.Date, Id = td.Id, Latitude = td.Latitude, Longitude = td.Longitude }).ToList(), User = ToUserResponse(t.User) }).ToList(), User = ToUserResponse(DipEntity.User) }); }
public async Task <IActionResult> Edit(int id, DipEntity dipEntity) { if (id != dipEntity.Id) { return(NotFound()); } if (ModelState.IsValid) { dipEntity.Plaque = dipEntity.Plaque.ToUpper(); _context.Update(dipEntity); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(dipEntity)); }
public async Task <IActionResult> GetDipEntity([FromRoute] string plaque) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DipEntity DipEntity = await _context.Dips .Include(t => t.User) // Driver .Include(t => t.Trips) .ThenInclude(t => t.TripDetails) .Include(t => t.Trips) .ThenInclude(t => t.User) // Passanger .FirstOrDefaultAsync(t => t.Plaque == plaque); if (DipEntity == null) { return(NotFound()); } return(Ok(_converterHelper.ToDipResponse(DipEntity))); }