/// <summary> /// Получить id груза по коду ЕТ СНГ /// </summary> /// <param name="id_cargo"></param> /// <returns></returns> public int DefinitionIDCargo(int id_cargo) { ReferenceCargo ref_cargo = g_ref.GetReferenceCargoOfCodeETSNG(id_cargo); if (ref_cargo == null) { Code_Cargo cargo = rw_ref.GetCargos_ETSNG(id_cargo, false); if (cargo == null) { cargo = rw_ref.GetCargos_ETSNG(id_cargo, true); if (cargo == null) { return(0); } } ReferenceCargo new_cargo = new ReferenceCargo() { IDCargo = 0, Name = cargo.ETSNG.Length > 200 ? cargo.ETSNG.Remove(199).Trim() : cargo.ETSNG.Trim(), NameFull = cargo.ETSNG.Length > 500 ? cargo.ETSNG.Remove(499).Trim() : cargo.ETSNG.Trim(), ETSNG = id_cargo }; int res = g_ref.SaveReferenceCargo(new_cargo); if (res > 0) { return(res); } else { return(0); } } return(ref_cargo.IDCargo); }
/// <summary> /// Удалить /// </summary> /// <param name="IDCargo"></param> /// <returns></returns> public ReferenceCargo DeleteReferenceCargo(int IDCargo) { ReferenceCargo dbEntry = context.ReferenceCargo.Find(IDCargo); if (dbEntry != null) { context.ReferenceCargo.Remove(dbEntry); try { context.SaveChanges(); } catch (Exception e) { LogRW.LogError(e, "DeleteReferenceCargo", eventID); return(null); } } return(dbEntry); }
/// <summary> /// Добавить или править /// </summary> /// <param name="ReferenceCargo"></param> /// <returns></returns> public int SaveReferenceCargo(ReferenceCargo ReferenceCargo) { ReferenceCargo dbEntry; if (ReferenceCargo.IDCargo == 0) { dbEntry = new ReferenceCargo() { IDCargo = 0, Name = ReferenceCargo.Name, NameFull = ReferenceCargo.NameFull, ETSNG = ReferenceCargo.ETSNG }; context.ReferenceCargo.Add(dbEntry); } else { dbEntry = context.ReferenceCargo.Find(ReferenceCargo.IDCargo); if (dbEntry != null) { dbEntry.Name = ReferenceCargo.Name; dbEntry.NameFull = ReferenceCargo.NameFull; dbEntry.ETSNG = ReferenceCargo.ETSNG; } } try { context.SaveChanges(); } catch (Exception e) { LogRW.LogError(e, "SaveReferenceCargo", eventID); return(-1); } return(dbEntry.IDCargo); }
public int SaveReferenceCargo(ReferenceCargo reference_cargo) { return(rep_cargo.SaveReferenceCargo(reference_cargo)); }