private MSD1 mapMSD1DataToMSD1(string Id) { Msd1Data msd1Data = _context.Msd1Data.First(x => x.Msd1Id == Id) ?? new Msd1Data(); MSD1 msd1 = new MSD1() { Imo = msd1Data.Imo, ShipName = msd1Data.ShipName ?? _helperService.GetShipNameByIMO(msd1Data.Imo), Deadweight = _helperService.GetDeadweightByIMO(msd1Data.Imo), Year = msd1Data.Year, Quarter = msd1Data.Quarter, AssociatedPort = _helperService.GetPortNameByCode(msd1Data.AssociatedPort) ?? msd1Data.AssociatedPort, ReportingPort = _helperService.GetPortNameByCode(msd1Data.ReportingPort) ?? msd1Data.ReportingPort, NumVoyages = msd1Data.NumVoyages, IsInbound = msd1Data.IsInbound, Msd1Id = msd1Data.Msd1Id, AgentSenderID = msd1Data.AgentSenderId, AgentCompanyName = _helperService.GetCompanyNameBySenderID(msd1Data.AgentSenderId) ?? string.Empty, LineSenderID = msd1Data.LineSenderId, LineCompanyName = _helperService.GetCompanyNameBySenderID(msd1Data.LineSenderId) ?? string.Empty, FlagCode = _helperService.GetFlagCodeFromIMO(msd1Data.Imo) ?? string.Empty, RecordRef = msd1Data.RecordRef, CargoSummary = MapMsd1CargoSummaryToCargoItem(msd1Data.Msd1Id) }; return(msd1); }
public async Task <IActionResult> OnPostAsync() { try { CargoSummary = _context.Msd1CargoSummary.Where(x => x.Id == int.Parse(TempData.Peek("SumId").ToString())) .First(); CargoSummary.CategoryCode = CategoryCode; CargoSummary.UnitsWithCargo = UnitsWithCargo; CargoSummary.UnitsWithoutCargo = UnitsWithoutCargo; CargoSummary.TotalUnits = TotalUnits; CargoSummary.GrossWeight = GrossWeight; CargoSummary.Description = Description; await UpdateLastUpdatedAsync(); var totalWeightAllowed = _helperService.GetDeadweightByIMO(Msd.Imo) * Msd.NumVoyages; if (CargoSummary.GrossWeight > totalWeightAllowed) { ModelState.AddModelError("GrossWeight", "The Gross Weight is larger than this ship can carry"); return(Page()); } if (!DoesCategoryCodeExist(CargoSummary.CategoryCode)) { ModelState.AddModelError("CategoryCode", $"The Category Code {CargoSummary.CategoryCode} is not valid"); return(Page()); } _context.SaveChanges(); TempData.Put("EditSuccess", "Cargo summary has been successfully amended"); TempData["Msd1Id"] = CargoSummary.Msd1Id; } catch (Exception e) { _logger.LogError(e, e.Message); return(RedirectToPage("/Summaries/ViewSummary", new { area = "Admin" })); } return(RedirectToPage("/Summaries/ViewSummary", new { area = "Admin" })); }