예제 #1
0
        public static int CreateTestObjects()
        {

            #region REGIONS
            CCountry Country = new CCountry(DatabaseContext)
            {
                FullDescription = "Россия",
                ShortDescription = "Россия",
                Name = "Россия",
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(Provider),
                ModificatonDate = DateTime.Now,
                Parent = CEmbeddedObjectsConsts.CONST_FOLDER_REGIONS_KEY,
                Status = EnMetaobjectStatus.EEnabled,
                System = false
            };

            var R = Country.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            CState State = new CState(DatabaseContext)
            {
                FullDescription = "Пермский край",
                ShortDescription = "Пермский край",
                Name = "Пермский край",
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(Provider),
                ModificatonDate = DateTime.Now,
                Parent = Country.Key,
                Status = EnMetaobjectStatus.EEnabled,
                System = false                
            };

            R = State.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            CCity City = new CCity(DatabaseContext)
            {
                FullDescription = "Пермь",
                ShortDescription = "Пермь",
                Name = "Пермь",
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(Provider),
                ModificatonDate = DateTime.Now,
                Parent = State.Key,
                Status = EnMetaobjectStatus.EEnabled,
                System = false,
                Coordinates = ""
            };

            R = City.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            #endregion

            #region ORGANIZATIONS
            COrganizationNetwork OrganizationNetwork = new COrganizationNetwork(DatabaseContext)
            {
                FullDescription = "Сеть организаций",
                ShortDescription = "Сеть организаций",
                Name = "Сеть организаций",
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(Provider),
                ModificatonDate = DateTime.Now,
                Parent = CEmbeddedObjectsConsts.CONST_FOLDER_MENUS_KEY,
                Status = EnMetaobjectStatus.EEnabled,
                System = false,
                Email = "Email",
                Url = ""
            };
            R = OrganizationNetwork.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            COrganization Organization = new COrganization(DatabaseContext)
            {
                FullDescription = "Организация",
                ShortDescription = "Организация",
                Name = "Организация",
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(Provider),
                ModificatonDate = DateTime.Now,
                Parent = CEmbeddedObjectsConsts.CONST_FOLDER_MENUS_KEY,
                Status = EnMetaobjectStatus.EEnabled,
                System = false
            };
            R = Organization.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            cMenu.Metaobjects.Linq.CMetaobjectLink Link = new Metaobjects.Linq.CMetaobjectLink()
            {
                LinkedObjectKey = Organization.Key,
                LinkType = EnMetaobjectLinkType.ESimple,
                LinkValue = 1,
                SourceObjectKey = City.Key
            };
            R = Link.LinkInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            #endregion

            #region SERVICES
            CMenuService Service1 = new CMenuService(DatabaseContext)
            {
                FullDescription = "Товар 1",
                ShortDescription = "Товар 1",
                Name = "Товар 1",
                Composition = "Состав",
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(Provider),
                ModificatonDate = DateTime.Now,
                Parent = CEmbeddedObjectsConsts.CONST_FOLDER_SERVICES_KEY,
                Status = EnMetaobjectStatus.EEnabled,
                System = false
            };
            R = Service1.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            CMenuService Service2 = new CMenuService(DatabaseContext)
            {
                FullDescription = "Товар 2",
                ShortDescription = "Товар 2",
                Name = "Товар 2",
                Composition = "Состав",
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(Provider),
                ModificatonDate = DateTime.Now,
                Parent = CEmbeddedObjectsConsts.CONST_FOLDER_SERVICES_KEY,
                Status = EnMetaobjectStatus.EEnabled,
                System = false
            };
            R = Service2.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            CMenuServiceAmount Amount1 = new CMenuServiceAmount(DatabaseContext)
            {
                FullDescription = "Порция 1.1",
                ShortDescription = "ТПорция 1.1",
                Name = "Порция 1.1",
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(Provider),
                ModificatonDate = DateTime.Now,
                Parent = Service1.Key,
                Status = EnMetaobjectStatus.EEnabled,
                System = false,
                Price = 100,
                Amount = 200,
                Units = "мг",
                TimeAmount = new TimeSpan(0, 10, 0)
            };
            R = Amount1.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            CMenuServiceAmount Amount2 = new CMenuServiceAmount(DatabaseContext)
            {
                FullDescription = "Порция 2.1",
                ShortDescription = "ТПорция 2.1",
                Name = "Порция 2.1",
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(Provider),
                ModificatonDate = DateTime.Now,
                Parent = Service2.Key,
                Status = EnMetaobjectStatus.EEnabled,
                System = false,
                Price = 200,
                Amount = 300,
                Units = "г",
                TimeAmount = new TimeSpan(0, 20, 0)
            };
            R = Amount2.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;
            #endregion

            #region MENU
            CMenu Menu = new CMenu(DatabaseContext)
            {
                FullDescription = "Меню",
                ShortDescription = "Меню",
                Name = "Меню",
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(Provider),
                ModificatonDate = DateTime.Now,
                Parent = Organization.Key,
                Status = EnMetaobjectStatus.EEnabled,
                System = false,
                Primary = true
            };
            R = Menu.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            CCategory Category = new CCategory()
            {
                FullDescription = "Категория",
                ShortDescription = "Категория",
                Name = "Категория",
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(Provider),
                ModificatonDate = DateTime.Now,
                Parent = Menu.Key,
                Status = EnMetaobjectStatus.EEnabled,
                System = false
            };
            R = Category.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            CMetaobjectShortcut Shortcut = new CMetaobjectShortcut(DatabaseContext)
            {
                FullDescription = "Ссылка на порцию 1.1",
                ShortDescription = "Ссылка на порцию 1.1",
                Name = "Ссылка на порцию 1.1",
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(Provider),
                ModificatonDate = DateTime.Now,
                Parent = Category.Key,
                Status = EnMetaobjectStatus.EEnabled,
                System = false,
                SourceObjectKey = Amount1.Key
            };
            R = Shortcut.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            CMetaobjectShortcut Shortcut2 = new CMetaobjectShortcut(DatabaseContext)
            {
                FullDescription = "Ссылка на порцию 1.2",
                ShortDescription = "Ссылка на порцию 1.2",
                Name = "Ссылка на порцию 1.2",
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(Provider),
                ModificatonDate = DateTime.Now,
                Parent = Category.Key,
                Status = EnMetaobjectStatus.EEnabled,
                System = false,
                SourceObjectKey = Amount2.Key
            };
            R = Shortcut2.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            #endregion

            #region TABLES
            COrganizationTable Table = new COrganizationTable(DatabaseContext)
            {
                FullDescription = "Стол",
                ShortDescription = "Стол",
                Name = "Стол",
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(Provider),
                ModificatonDate = DateTime.Now,
                Parent = CEmbeddedObjectsConsts.CONST_FOLDER_SERVICES_KEY,
                Status = EnMetaobjectStatus.EEnabled,
                System = false
            };
            R = Table.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            Link = new Metaobjects.Linq.CMetaobjectLink()
            {
                LinkedObjectKey = Table.Key,
                LinkType = EnMetaobjectLinkType.ESimple,
                LinkValue = 1,
                SourceObjectKey = Organization.Key
            };
            R = Link.LinkInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            #endregion

            try
            { DatabaseContext.SubmitChanges(); }
            catch (Exception Exception)
            {
                throw new Exception(Exception.Message);
                return CErrors.ERR_DB_INSERT_OBJECT;
            }

            return CErrors.ERR_SUC;
        }
예제 #2
0
        protected CFunctionResult _getServiceInformation(string UserIdentity, string Passhash, Guid SessionID, Guid ServiceID)
        {
            Dictionary<string, object> InputParameters = new Dictionary<string, object>();
            InputParameters.Add("UserIdentity", UserIdentity);
            InputParameters.Add("Passhash", Passhash);
            InputParameters.Add("SessionID", SessionID.ToString().ToUpper());
            InputParameters.Add("ServiceID", ServiceID);

            CFunctionResult R = new CFunctionResult()
            {
                FunctionID = "GetServiceInformation",
                InputParameters = InputParameters,
                ResultType = Communication.EnFunctionResultType.ESuccess
            };

            if (ServiceID == null)
            {
                R = CServerHelper.sCompileFunctionResult("GetServiceInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_ID_NULL", CultureInfo.CurrentCulture), null);
                return R;
            }

            CFunctionResult UserResult = CServerHelper.sCheckUser(UserIdentity, Passhash, SessionID);
            if (UserResult.ResultType != Communication.EnFunctionResultType.ESuccess)
            {
                UserResult.FunctionID = "GetServiceInformation";
                UserResult.InputParameters = InputParameters;
                return UserResult;
            }

            CMetaobjectShortcut ServiceShortcut = new CMetaobjectShortcut(ServiceID, CServerEnvironment.DataContext);
            if (ServiceShortcut.Key == CDBConst.CONST_OBJECT_EMPTY_KEY)
            {
                R = CServerHelper.sCompileFunctionResult("GetServiceInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_UNABLE_TO_FIND", CultureInfo.CurrentCulture), null);
                return R;
            }

            var ServiceKey = ServiceShortcut.SourceObjectKey;

            CMenuService Service = new CMenuService(ServiceKey, CServerEnvironment.DataContext);
            if (Service.ID == Guid.Empty)
            {
                R = CServerHelper.sCompileFunctionResult("GetServiceInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_UNABLE_TO_FIND", CultureInfo.CurrentCulture), null);
                return R;
            }

            Service.GetChildren(CServerEnvironment.DataContext, false);
            R.Content = Service;

            return R;
        }