예제 #1
0
        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));
        }
예제 #2
0
 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)
     });
 }
예제 #3
0
        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));
        }
예제 #4
0
        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)));
        }