Ejemplo n.º 1
0
        public override bool UpdateCustomFieldData(Guid objectCustomFieldId, object value, CustomFieldTypeFlag flag)
        {
            UnitOfWork uow = null;

            try
            {
                uow = XpoHelper.GetNewUnitOfWork();
                //Get ObjectCustomField by Id
                ObjectCustomField objectCustomField =
                    uow.GetObjectByKey <ObjectCustomField>(objectCustomFieldId);
                if (objectCustomField.ObjectCustomFieldDatas.Count > 0 && objectCustomField.ObjectCustomFieldDatas.FirstOrDefault() != null)
                {
                    objectCustomField.CustomFieldType = flag.Value;
                    uow.FlushChanges();
                    CustomFieldDataInt customFieldData =
                        (CustomFieldDataInt)objectCustomField.ObjectCustomFieldDatas
                        .FirstOrDefault().CustomFieldDataId;

                    customFieldData.IntValue = (int)value;

                    ObjectBO objectBO = new ObjectBO();
                    DynamicObjectListSerializeDataItem dataitem = new DynamicObjectListSerializeDataItem()
                    {
                        ObjectCustomFieldId = objectCustomFieldId,
                        CustomFieldName     = customFieldData.CustomFieldId.Name,
                        CustomFieldData     = customFieldData.IntValue.ToString()
                    };
                    objectBO.SetDynamicObjectListItem(uow, objectCustomField.ObjectId.ObjectId, dataitem);

                    uow.CommitChanges();
                }
                else
                {
                    throw new Exception();
                }
                return(true);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (uow != null)
                {
                    uow.Dispose();
                }
            }

            throw new NotImplementedException();
        }
        public bool UpdateSelecteCustomFieldAllDataItems(Guid objectCustomFieldId, List <Guid> list)
        {
            using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
            {
                try
                {
                    ObjectCustomField objectCustomField =
                        uow.GetObjectByKey <ObjectCustomField>(objectCustomFieldId);

                    if (objectCustomField == null)
                    {
                        throw new Exception("The key is not exist in ObjectCustomField");
                    }

                    int cnt = objectCustomField.ObjectCustomFieldDatas.Count;
                    if (objectCustomField.ObjectCustomFieldDatas != null && cnt > 0)
                    {
                        uow.Delete(objectCustomField.ObjectCustomFieldDatas);
                        uow.FlushChanges();
                    }

                    foreach (Guid g in list)
                    {
                        AddItemToSelectedCustomFieldDataItems(uow, objectCustomFieldId, g);
                    }

                    uow.FlushChanges();

                    objectCustomField =
                        uow.GetObjectByKey <ObjectCustomField>(objectCustomFieldId);

                    string displayText = String.Empty;
                    foreach (var item in objectCustomField.ObjectCustomFieldDatas)
                    {
                        if (objectCustomField.ObjectCustomFieldDatas.IndexOf(item) == 0)
                        {
                            displayText = ((CustomFieldDataString)item.CustomFieldDataId).StringValue;
                        }
                        else
                        {
                            displayText += String.Format(";{0}",
                                                         ((CustomFieldDataString)item.CustomFieldDataId).StringValue);
                        }
                    }

                    ObjectBO objectBO = new ObjectBO();
                    DynamicObjectListSerializeDataItem dataitem = new DynamicObjectListSerializeDataItem()
                    {
                        ObjectCustomFieldId = objectCustomFieldId,
                        CustomFieldName     = objectCustomField.ObjectTypeCustomFieldId.CustomFieldId.Name,
                        CustomFieldData     = displayText
                    };
                    objectBO.SetDynamicObjectListItem(uow, objectCustomField.ObjectId.ObjectId, dataitem);
                    uow.CommitChanges();
                    return(true);
                }
                catch
                {
                    //uow.ExplicitRollbackTransaction();
                    throw;
                }
            }
        }
        public bool UpdateCustomFieldData(Guid objectCustomFieldId, Guid customFieldDataStringId)
        {
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();
                //Get ObjectCustomField by Id
                session.BeginTransaction();

                ObjectCustomField objectCustomField =
                    session.GetObjectByKey <ObjectCustomField>(objectCustomFieldId);

                if (objectCustomField == null)
                {
                    throw new Exception("The key is not exist in ObjectCustomField");
                }

                CustomFieldDataString customFieldDataString =
                    session.GetObjectByKey <CustomFieldDataString>(customFieldDataStringId);

                if (customFieldDataString == null)
                {
                    session.Delete(objectCustomField.ObjectCustomFieldDatas);
                    DynamicObjectListSerializeDataItem dataitem = new DynamicObjectListSerializeDataItem()
                    {
                        ObjectCustomFieldId = objectCustomFieldId,
                        CustomFieldName     = null,
                        CustomFieldData     = null
                    };
                    ObjectBO objectBO = new ObjectBO();
                    objectBO.SetDynamicObjectListItem(session, objectCustomField.ObjectId.ObjectId, dataitem);
                    //throw new Exception("The key is not exist in CustomFieldDataString");
                }
                else
                {
                    if (objectCustomField.ObjectCustomFieldDatas != null && objectCustomField.ObjectCustomFieldDatas.Count > 0)
                    {
                        for (int i = 0; i < objectCustomField.ObjectCustomFieldDatas.Count; i++)
                        {
                            objectCustomField.ObjectCustomFieldDatas[i].Delete();
                        }
                    }
                    ObjectCustomFieldData ocfd = new ObjectCustomFieldData(session);
                    ocfd.ObjectCustomFieldId = objectCustomField;
                    ocfd.CustomFieldDataId   = customFieldDataString;
                    ocfd.Save();

                    ObjectBO objectBO = new ObjectBO();
                    DynamicObjectListSerializeDataItem dataitem = new DynamicObjectListSerializeDataItem()
                    {
                        ObjectCustomFieldId = objectCustomFieldId,
                        CustomFieldName     = customFieldDataString.CustomFieldId.Name,
                        CustomFieldData     = customFieldDataString.StringValue
                    };
                    objectBO.SetDynamicObjectListItem(session, objectCustomField.ObjectId.ObjectId, dataitem);
                }
                session.CommitTransaction();
                return(true);
            }
            catch (Exception)
            {
                session.RollbackTransaction();
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Ejemplo n.º 4
0
        public bool UpdateCustomFieldData(Guid objectCustomFieldId,
                                          IEnumerable <Guid> refIds,
                                          PredefinitionCustomFieldTypeEnum preDefinitionType,
                                          CustomFieldTypeFlag flag)
        {
            bool       ret = false;
            UnitOfWork uow = null;

            try
            {
                uow = XpoHelper.GetNewUnitOfWork();

                ObjectCustomField objectCustomField = uow.GetObjectByKey <ObjectCustomField>(objectCustomFieldId);

                objectCustomField.CustomFieldType = flag.Value;

                uow.FlushChanges();

                NAS.DAL.CMS.ObjectDocument.CustomField customField =
                    objectCustomField.ObjectTypeCustomFieldId.CustomFieldId;

                //Delete all old data
                uow.Delete(objectCustomField.ObjectCustomFieldDatas);
                uow.FlushChanges();
                //Insert new data for object
                if (refIds != null)
                {
                    foreach (var refId in refIds)
                    {
                        PredefinitionData predefinitionData = new PredefinitionData(uow)
                        {
                            CustomFieldId     = customField,
                            PredefinitionType =
                                Enum.GetName(typeof(PredefinitionCustomFieldTypeEnum), preDefinitionType),
                            RefId = refId
                        };
                        //predefinitionData.Save();

                        ObjectCustomFieldData objectCustomFieldData = new ObjectCustomFieldData(uow)
                        {
                            CustomFieldDataId   = predefinitionData,
                            ObjectCustomFieldId = objectCustomField
                        };
                        //objectCustomFieldData.Save();

                        uow.FlushChanges();
                    }
                }

                ICustomFieldDataPreDefinitionDataGetter getter = GetDataGetter(preDefinitionType);
                ObjectBO objectBO = new ObjectBO();
                DynamicObjectListSerializeDataItem dataitem = new DynamicObjectListSerializeDataItem()
                {
                    ObjectCustomFieldId = objectCustomFieldId,
                    CustomFieldName     = customField.Name,
                    CustomFieldData     = getter.GetData(objectCustomFieldId).ToString()
                };
                objectBO.SetDynamicObjectListItem(uow, objectCustomField.ObjectId.ObjectId, dataitem);

                uow.CommitChanges();
                ret = true;
                return(ret);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (uow != null)
                {
                    uow.Dispose();
                }
            }
        }