Esempio n. 1
0
 public bool UpdateCMSObjects(Session session, Guid CMSObjectTypeId)
 {
     try
     {
         //Get object type
         NAS.DAL.CMS.ObjectDocument.ObjectType CMSObjectType =
             session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.ObjectType>(CMSObjectTypeId);
         //Insert new customfield for all object
         if (CMSObjectType.ObjectTypeCustomFields != null)
         {
             foreach (var objectTypeCustomField in CMSObjectType.ObjectTypeCustomFields)
             {
                 //If is new custom field of the object type
                 if (objectTypeCustomField.ObjectCustomFields == null ||
                     objectTypeCustomField.ObjectCustomFields.Count == 0)
                 {
                     //Attach new custom field for all cms object of the object type if exist
                     if (CMSObjectType.Objects != null)
                     {
                         foreach (var CMSObject in CMSObjectType.Objects)
                         {
                             AttachObjectCustomFieldWithDefaultValue(session, CMSObject, objectTypeCustomField, CustomFieldTypeFlag.CUSTOM_FIELD_TYPE_DEFAULT);
                         }
                     }
                 }
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Tìm đối tượng CMS object của InventoryJournal
        /// </summary>
        /// <param name="InventoryJournalId"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public NAS.DAL.CMS.ObjectDocument.Object GetCMSInventoryJournal(
            Guid InventoryJournalId,
            ObjectTypeEnum type)
        {
            if (type != ObjectTypeEnum.INVENTORY_IN && type != ObjectTypeEnum.INVENTORY_MOVE && type != ObjectTypeEnum.INVENTORY_OUT)
            {
                throw new Exception("The Type is invalid");
            }

            if (InventoryJournalId != null && !InventoryJournalId.Equals(Guid.Empty))
            {
                NAS.DAL.CMS.ObjectDocument.Object cmsObject = null;
                using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                {
                    InventoryJournal       journal       = uow.GetObjectByKey <InventoryJournal>(InventoryJournalId);
                    InventoryJournalObject journalObject =
                        journal.InventoryJournalObjects.FirstOrDefault();
                    if (journalObject == null)
                    {
                        ObjectBO objectBO = new ObjectBO();
                        cmsObject = objectBO.CreateCMSObject(uow, type);
                        InventoryJournalObject newJournalObject = new InventoryJournalObject(uow)
                        {
                            ObjectId           = cmsObject,
                            InventoryJournalId = journal
                        };

                        NAS.DAL.CMS.ObjectDocument.ObjectType objectType
                            = uow.FindObject <ObjectType>(new BinaryOperator("Name", Enum.GetName(typeof(ObjectTypeEnum), type)));

                        if (objectType == null)
                        {
                            throw new Exception("The OjectType is not exist in system");
                        }

                        InventoryJournalCustomType newJournalCustomType = new InventoryJournalCustomType(uow)
                        {
                            ObjectTypeId       = objectType,
                            InventoryJournalId = journal
                        };

                        newJournalCustomType.Save();

                        uow.CommitChanges();
                    }
                    else
                    {
                        cmsObject = journalObject.ObjectId;
                    }
                    return(cmsObject);
                }
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
0
        public NAS.DAL.CMS.ObjectDocument.Object CreateCMSObject(Session session, Guid CMSObjectTypeId)
        {
            try
            {
                //Get object type
                NAS.DAL.CMS.ObjectDocument.ObjectType CMSObjectType =
                    session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.ObjectType>(CMSObjectTypeId);

                string objectTypeCode = CMSObjectType.Name;

                ObjectTypeEnum objectType = (ObjectTypeEnum)Enum.Parse(typeof(ObjectTypeEnum), objectTypeCode);

                return(CreateCMSObject(session, objectType));
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 4
0
        public NAS.DAL.CMS.ObjectDocument.Object CreateCMSObject(Session session,
                                                                 ObjectTypeEnum type,
                                                                 params ObjectCustomFieldOption[] options)
        {
            NAS.DAL.CMS.ObjectDocument.Object CMSObject = null;
            try
            {
                //Get object type
                NAS.DAL.CMS.ObjectDocument.ObjectType CMSObjectType = ObjectType.GetDefault(session, type);
                //Create new CMS Object
                CMSObject = new DAL.CMS.ObjectDocument.Object(session)
                {
                    ObjectId     = Guid.NewGuid(),
                    ObjectTypeId = CMSObjectType
                };
                CMSObject.Save();

                foreach (var objectTypeCustomField in CMSObjectType.ObjectTypeCustomFields)
                {
                    CustomFieldTypeFlag flag = CustomFieldTypeFlag.CUSTOM_FIELD_TYPE_DEFAULT;
                    if (options.Length > 0)
                    {
                        ObjectCustomFieldOption option =
                            options.Where(r => r.CustomFieldId == objectTypeCustomField.CustomFieldId.CustomFieldId).FirstOrDefault();
                        if (option != null)
                        {
                            flag = option.ObjectCustomFieldFlag;
                        }
                    }
                    AttachObjectCustomFieldWithDefaultValue(session, CMSObject, objectTypeCustomField, flag);
                }
                return(CMSObject);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Tìm đối tượng CMS object của InventoryJournal
        /// </summary>
        /// <typeparam name="T">is NAS.DAL.Inventory.Command.InventoryCommandFinancialTransaction
        ///         or NAS.DAL.Inventory.Command.InventoryCommandItemTransaction
        /// </typeparam>
        /// <param name="transactionId"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public NAS.DAL.CMS.ObjectDocument.Object GetCMSTransaction <T>(
            Guid transactionId,
            ObjectTypeEnum type)
        {
            if (type != ObjectTypeEnum.INVENTORY_IN && type != ObjectTypeEnum.INVENTORY_MOVE && type != ObjectTypeEnum.INVENTORY_OUT)
            {
                throw new Exception("The Type is invalid");
            }

            if (!typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandFinancialTransaction)) &&
                !typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandItemTransaction)))
            {
                throw new Exception("The Generic Type is invalid");
            }

            if (transactionId != null && !transactionId.Equals(Guid.Empty))
            {
                NAS.DAL.CMS.ObjectDocument.Object cmsObject = null;
                using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                {
                    if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandItemTransaction)))
                    {
                        InventoryCommandItemTransaction transaction       = uow.GetObjectByKey <InventoryCommandItemTransaction>(transactionId);
                        InventoryTransactionObject      transactionObject =
                            transaction.InventoryTransactionObjects.FirstOrDefault();
                        if (transactionObject == null)
                        {
                            ObjectBO objectBO = new ObjectBO();
                            cmsObject = objectBO.CreateCMSObject(uow, type);
                            InventoryTransactionObject newTransactionObject = new InventoryTransactionObject(uow)
                            {
                                ObjectId = cmsObject,
                                InventoryTransactionId = transaction
                            };

                            NAS.DAL.CMS.ObjectDocument.ObjectType objectType
                                = uow.FindObject <ObjectType>(new BinaryOperator("Name", Enum.GetName(typeof(ObjectTypeEnum), type)));

                            if (objectType == null)
                            {
                                throw new Exception("The OjectType is not exist in system");
                            }

                            InventoryTransactionCustomType newTransactionCustomType = new InventoryTransactionCustomType(uow)
                            {
                                ObjectTypeId           = objectType,
                                InventoryTransactionId = transaction
                            };

                            newTransactionCustomType.Save();
                            uow.CommitChanges();
                        }
                        else
                        {
                            cmsObject = transactionObject.ObjectId;
                        }
                        return(cmsObject);
                    }
                    else
                    {
                        InventoryCommandFinancialTransaction transaction = uow.GetObjectByKey <InventoryCommandFinancialTransaction>(transactionId);
                        TransactionObject transactionObject =
                            transaction.TransactionObjects.FirstOrDefault();
                        if (transactionObject == null)
                        {
                            ObjectBO objectBO = new ObjectBO();
                            cmsObject = objectBO.CreateCMSObject(uow, type);
                            TransactionObject newTransactionObject = new TransactionObject(uow)
                            {
                                ObjectId      = cmsObject,
                                TransactionId = transaction
                            };
                            uow.CommitChanges();
                        }
                        else
                        {
                            cmsObject = transactionObject.ObjectId;
                        }
                        return(cmsObject);
                    }
                }
            }
            else
            {
                return(null);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Tạo dữ liệu cho CMS Object Inventory
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="uow"></param>
        /// <param name="InventoryObjectId"></param>
        /// <param name="CMSObjectType"></param>
        public void PopulateCMSObjecForInventoryObject <T>(
            UnitOfWork uow,
            Guid InventoryObjectId,
            DAL.CMS.ObjectDocument.ObjectTypeEnum CMSObjectType)
        {
            ObjectBO bo = new ObjectBO();

            if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommand)))
            {
                NAS.DAL.Inventory.Command.InventoryCommand inventoryObject =
                    uow.GetObjectByKey <NAS.DAL.Inventory.Command.InventoryCommand>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o   = bo.CreateCMSObject(uow, CMSObjectType);
                InventoryCommandObject            ICO = new InventoryCommandObject(uow);
                ICO.ObjectId           = o;
                ICO.InventoryCommandId = (inventoryObject as NAS.DAL.Inventory.Command.InventoryCommand);
                ICO.Save();
                NAS.DAL.CMS.ObjectDocument.ObjectType type =
                    NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType);
                if (type == null)
                {
                    throw new Exception("The ObjectType is not exist in system");
                }

                InventoryCommandCustomType ICCT = new InventoryCommandCustomType(uow);
                ICCT.ObjectTypeId       = type;
                ICCT.InventoryCommandId = (inventoryObject as NAS.DAL.Inventory.Command.InventoryCommand);
                ICCT.Save();
            }
            else if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandItemTransaction)))
            {
                InventoryCommandItemTransaction transactionObject =
                    uow.GetObjectByKey <InventoryCommandItemTransaction>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o   = bo.CreateCMSObject(uow, CMSObjectType);
                InventoryTransactionObject        ITO = new InventoryTransactionObject(uow);
                ITO.ObjectId = o;
                ITO.InventoryTransactionId = (transactionObject as NAS.DAL.Inventory.Journal.InventoryTransaction);
                ITO.Save();

                NAS.DAL.CMS.ObjectDocument.ObjectType type =
                    NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType);
                InventoryTransactionCustomType ITCT = new InventoryTransactionCustomType(uow);
                ITCT.ObjectTypeId           = type;
                ITCT.InventoryTransactionId = (transactionObject as NAS.DAL.Inventory.Journal.InventoryTransaction);
                ITCT.Save();
            }
            else if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandFinancialTransaction)))
            {
                InventoryCommandFinancialTransaction transactionObject =
                    uow.GetObjectByKey <InventoryCommandFinancialTransaction>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o = bo.CreateCMSObject(uow, CMSObjectType);
                TransactionObject TO = new TransactionObject(uow);
                TO.ObjectId      = o;
                TO.TransactionId = (transactionObject as Transaction);
                TO.Save();
            }
            else if (typeof(T).Equals(typeof(NAS.DAL.Accounting.Journal.GeneralJournal)))
            {
                GeneralJournal journalObject =
                    uow.GetObjectByKey <GeneralJournal>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o = bo.CreateCMSObject(uow, CMSObjectType);
                GeneralJournalObject GJO            = new GeneralJournalObject(uow);
                GJO.ObjectId         = o;
                GJO.GeneralJournalId = (journalObject as GeneralJournal);
                GJO.Save();
                NAS.DAL.CMS.ObjectDocument.ObjectType type =
                    NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType);
                GeneralJournalCustomType GJCT = new GeneralJournalCustomType(uow);
                GJCT.ObjectTypeId     = type;
                GJCT.GeneralJournalId = (journalObject as GeneralJournal);
                GJCT.Save();
            }
            else if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Journal.InventoryJournal)))
            {
                InventoryJournal journalObject =
                    uow.GetObjectByKey <InventoryJournal>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o   = bo.CreateCMSObject(uow, CMSObjectType);
                InventoryJournalObject            ITO = new InventoryJournalObject(uow);
                ITO.ObjectId           = o;
                ITO.InventoryJournalId = (journalObject as InventoryJournal);
                ITO.Save();

                NAS.DAL.CMS.ObjectDocument.ObjectType type =
                    NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType);
                InventoryJournalCustomType ITCT = new InventoryJournalCustomType(uow);
                ITCT.ObjectTypeId       = type;
                ITCT.InventoryJournalId = (journalObject as InventoryJournal);
                ITCT.Save();
            }
            uow.FlushChanges();
        }