public bool updateMasterUnitTypeOfItem(Guid itemId, Guid masterUnitTypeId) { using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork()) { try { NAS.DAL.Nomenclature.UnitItem.UnitType ut = uow.GetObjectByKey <NAS.DAL.Nomenclature.UnitItem.UnitType>(masterUnitTypeId); NAS.DAL.Nomenclature.Item.Item i = uow.GetObjectByKey <NAS.DAL.Nomenclature.Item.Item>(itemId); if (ut == null) { throw new Exception("The UnitType is not exist in system"); } if (i == null) { throw new Exception("The Item is not exist in system"); } if (i.itemUnitTypeConfigs == null || i.itemUnitTypeConfigs.Count == 0) { throw new Exception("The UnitTypes are blank with this item"); } IEnumerable <UnitType> tmpLst = i.itemUnitTypeConfigs.Select(o => o.UnitTypeId).Where(rs => rs.UnitTypeId == masterUnitTypeId); if (tmpLst == null || tmpLst.Count() == 0) { throw new Exception("The MasterUnitTypeId is not in ItemUnitTypeConfig"); } foreach (NAS.DAL.Nomenclature.Item.ItemUnitTypeConfig config in i.itemUnitTypeConfigs) { if (config.UnitTypeId.UnitTypeId.Equals(masterUnitTypeId)) { config.IsMaster = true; } else { config.IsMaster = false; } config.Save(); } uow.CommitChanges(); return(true); } catch { throw; } finally { uow.Dispose(); } } }
public NAS.DAL.Nomenclature.Item.ItemUnitTypeConfig getItemUnitTypeConfig(Session session, Guid itemId, Guid unitTypeId) { try { NAS.DAL.Nomenclature.UnitItem.UnitType ut = session.GetObjectByKey <NAS.DAL.Nomenclature.UnitItem.UnitType>(unitTypeId); NAS.DAL.Nomenclature.Item.Item i = session.GetObjectByKey <NAS.DAL.Nomenclature.Item.Item>(itemId); ItemUnitTypeConfig iutc = session.FindObject <ItemUnitTypeConfig>( CriteriaOperator.And( new BinaryOperator("UnitTypeId", ut, BinaryOperatorType.Equal), new BinaryOperator("ItemId", i, BinaryOperatorType.Equal) ) ); return(iutc); } catch { throw; } }