public async Task <Voy> ToVoyAsync(VoysViewModel model, bool isNew) { return(new Voy { Account = model.Account, Altitude = model.Altitude, Cargo = model.Cargo, Cargo_Charterer = model.Cargo_Charterer, Company = await _dataContext.Companies.FindAsync(model.Company_id), Consignee = model.Consignee, Contract = model.Contract, Employee = await _dataContext.Employees.FindAsync(model.Employ_id), Id = isNew ? 0 : model.Id, Eta = isNew ? DateTime.Today : model.Eta.ToUniversalTime(), Etb = isNew ? DateTime.Today : model.Etb.ToUniversalTime(), Etc = isNew ? DateTime.Today : model.Etc.ToUniversalTime(), Etd = isNew ? DateTime.Today : model.Etd.ToUniversalTime(), Facility = model.Facility, LastKnowPosition = isNew ? DateTime.Today : model.LastKnowPosition, Latitude = model.Latitude, Laycan = model.Laycan, Opinions = isNew ? new List <Opinion>() : model.Opinions, Owner_Charterer = model.Owner_Charterer, Pod = model.Pod, Pol = model.Pol, Port = await _dataContext.Ports.FindAsync(model.Port_id), Sf = model.Sf, Shipper = model.Shipper, Statuses = isNew ? new List <Status>() : model.Statuses, Vessel = await _dataContext.Vessels.FindAsync(model.Vessel_id), Voyimages = isNew ? new List <Voyimage>() : model.Voyimages, Voy_number = model.Voy_number, }); }
public async Task <IActionResult> EditVoy(VoysViewModel model) { if (ModelState.IsValid) { var voy = await _converterHelper.ToVoyAsync(model, false); _datacontext.Voys.Update(voy); await _datacontext.SaveChangesAsync(); return(RedirectToAction($"VoyList/{model.Company_id}")); } return(View(model)); }
public async Task <IActionResult> AddVoy(VoysViewModel model) { if (ModelState.IsValid) { var voy = await _converterHelper.ToVoyAsync(model, true); _datacontext.Voys.Add(voy); await _datacontext.SaveChangesAsync(); return(RedirectToAction($"VoyList/{model.Company_id}")); } model.Employee_list = _combosHelper.GetComboEmployees(); model.Vessel_list = _combosHelper.GetComboVessels(); model.Port_list = _combosHelper.GetComboPorts(); return(View(model)); }
public async Task <IActionResult> AddVoy(int?id) { var company = await _datacontext.Companies.FindAsync(id); if (id == null || company == null) { return(NotFound()); } var model = new VoysViewModel { Company_id = company.Id, Employee_list = _combosHelper.GetComboEmployees(), Port_list = _combosHelper.GetComboPorts(), Vessel_list = _combosHelper.GetComboVessels(), }; return(View(model)); }