Exemple #1
0
        public override void AfterApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.AfterApplyChanges(dbHelper, entity);

            if (entity.ChangeStatus.IsIn(EntityChangeTypes.Add, EntityChangeTypes.Modify))
            {
                //فعلا با ایجاد هر تعریف کالا، یک کالا هم ایجاد می کنیم.
                //بعدا وقتی امکان تعیین مشخصه ها مشخصه ها به تعریف کالا اضافه شد، باید به ازای ترکیب مشخصه ها کالا ایجاد شود

                if (!dbHelper.EntityExists("cmn.Stuff", string.Format("StuffDef = '{0}'", entity.GetFieldValue <Guid>("ID"))))
                {
                    var stuff = dbHelper.CreateNewEntity("cmn.Stuff");
                    stuff.SetFieldValue("StuffDef", entity.GetFieldValue <Guid>("ID"));
                    dbHelper.InsertEntity(stuff);
                }
            }
        }
Exemple #2
0
        public override void AfterApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.AfterApplyChanges(dbHelper, entity);

            var id = entity.GetFieldValue <Guid>("ID");

            if (entity.ChangeStatus == EntityChangeTypes.Add)
            {
                var afwOrganizationUnit = dbHelper.CreateNewEntity("afw.OrganizationUnit");
                afwOrganizationUnit.SetFieldValue("ID", id);
                afwOrganizationUnit.SetFieldValue("Name", entity.GetFieldValue <string>("Name"));
                afwOrganizationUnit.SetFieldValue("ParentOrganizationUnit", entity.GetFieldValue <Guid>("ParentOrganizationUnit"));

                dbHelper.InsertEntity(afwOrganizationUnit);
            }
            if (entity.ChangeStatus == EntityChangeTypes.Modify)
            {
                var afwOrganizationUnit = dbHelper.FetchSingleByID("afw.OrganizationUnit", id, null);

                if (afwOrganizationUnit == null)
                {
                    throw new AfwException("afwOrganizationUnit not found!");
                }

                afwOrganizationUnit.SetFieldValue("Name", entity.GetFieldValue <string>("Name"));
                afwOrganizationUnit.SetFieldValue("ParentOrganizationUnit", entity.GetFieldValue <Guid>("ParentOrganizationUnit"));

                dbHelper.UpdateEntity(afwOrganizationUnit);
            }
            if (entity.ChangeStatus == EntityChangeTypes.Delete)
            {
                var afwOrganizationUnit = dbHelper.FetchSingleByID("afw.OrganizationUnit", id, null);

                if (afwOrganizationUnit == null)
                {
                    throw new AfwException("afwOrganizationUnit not found!");
                }

                dbHelper.DeleteEntity(afwOrganizationUnit);
            }
        }
        public override void AfterApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.AfterApplyChanges(dbHelper, entity);

            if (entity.ChangeStatus != EntityChangeTypes.Delete)
            {
                new SalesCaseBL().UpdateSalesCaseLastActionTime(entity.GetFieldValue <Guid>("SalesCase"));
            }

            var connectedPersonID = entity.GetFieldValue <Guid>("ConnectedPerson");

            if (entity.ChangeStatus.IsIn(EntityChangeTypes.Add, EntityChangeTypes.Modify))
            {
                //ایجاد یا به روز رسانی اشخاص مرتبط در موجودیت مشتری
                var salesCase = dbHelper.FetchSingleByID("crm.SalesCase", entity.GetFieldValue <Guid>("SalesCase"), null);

                var personConnectedPerson = dbHelper.FetchSingle("cmn.PersonConnectedPerson",
                                                                 string.Format("ParentPerson = '{0}' and ConnectedPerson = '{1}'",
                                                                               salesCase.GetFieldValue <Guid>("Customer"), connectedPersonID), null);

                if (personConnectedPerson != null &&
                    personConnectedPerson.GetFieldValue <Guid?>("ConnectedPersonPost") != entity.GetFieldValue <Guid?>("ConnectedPersonPost"))
                {
                    personConnectedPerson.SetFieldValue("ConnectedPersonPost", entity.GetFieldValue <Guid?>("ConnectedPersonPost"));
                    dbHelper.UpdateEntity(personConnectedPerson);
                }
                else
                {
                    personConnectedPerson = dbHelper.CreateNewEntity("cmn.PersonConnectedPerson");
                    personConnectedPerson.SetFieldValue("ParentPerson", salesCase.GetFieldValue <Guid>("Customer"));
                    personConnectedPerson.SetFieldValue("ConnectedPerson", connectedPersonID);
                    personConnectedPerson.SetFieldValue("ConnectedPersonPost", entity.GetFieldValue <Guid?>("ConnectedPersonPost"));
                    dbHelper.InsertEntity(personConnectedPerson);
                }
            }
        }