public void InitializeObject(int groupCode) { _businessObject = (ItemGroups)Controller.ConnectionController.Instance.Company.GetBusinessObject(BoObjectTypes.oItemGroups); if (!_businessObject.GetByKey(groupCode)) { _newObject = true; } }
public void Save(Model.ItemGroupModel itemGroupModel) { int groupCode = Controller.ConnectionController.Instance.ExecuteSqlForObject <int>("GetItemGroupCode", itemGroupModel.GroupName); if (groupCode != 0) { itemGroupModel.GroupCode = groupCode; return; } ItemGroups itemGroup = (ItemGroups)Controller.ConnectionController.Instance.Company.GetBusinessObject(BoObjectTypes.oItemGroups); try { if (itemGroup.GetByKey(itemGroupModel.GroupCode)) { itemGroup.GroupName = itemGroupModel.GroupName; foreach (KeyValuePair <string, dynamic> userField in itemGroupModel.UserFields) { itemGroup.UserFields.Fields.Item(userField.Key).Value = userField.Value; } Controller.ConnectionController.Instance.VerifyBussinesObjectSuccess(); itemGroup.Update(); } else { itemGroup.GroupName = itemGroupModel.GroupName; //itemGroup.InventoryAccount = "1.01.01.01.01"; //itemGroup.CostAccount = "1.01.01.01.01"; //itemGroup.TransfersAccount = "1.01.01.01.01"; //itemGroup.VarianceAccount = "1.01.01.01.01"; //itemGroup.PriceDifferencesAccount = "1.01.01.01.01"; foreach (KeyValuePair <string, dynamic> userField in itemGroupModel.UserFields) { itemGroup.UserFields.Fields.Item(userField.Key).Value = userField.Value; } itemGroup.Add(); Controller.ConnectionController.Instance.VerifyBussinesObjectSuccess(); itemGroupModel.GroupCode = Controller.ConnectionController.Instance.LastObjectCode; } } finally { GC.Collect(); Marshal.ReleaseComObject(itemGroup); } }