/// <summary> /// Mapeia uma entidade para uma view-model de listagem /// </summary> /// <param name="entity">Instância da entidade</param> public static ManobraViewModel Map(this Manobra entity) { CarroViewModel carroModel = entity.Carro.Map(); ManobristaViewModel manobristaModel = entity.Manobrista.Map(); ManobraViewModel manobraModel = new ManobraViewModel() { Id = entity.Id, Entrada = entity.Entrada, Saida = entity.Saida, CarroId = entity.CarroId, ManobristaId = entity.ManobristaId, Carro = carroModel, Manobrista = manobristaModel }; return(manobraModel); }
public async Task <IActionResult> Create([Bind("CarroId,ManobristaId")] ManobraViewModel model) { if (ModelState.IsValid) { Manobra e = new Manobra() { ManobristaId = model.ManobristaId, CarroId = model.CarroId, Entrada = DateTime.Now }; await _manobra.AddAsync(e); await _work.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } await CarregaViewBag(); return(View(model)); }