Пример #1
0
        internal async Task <DataModelAndView> GetDataModelForView(RequestView rw, ExpandoObject initialParams)
        {
            var dmv = new DataModelAndView()
            {
                RequestView = rw
            };
            String loadProc = rw.LoadProcedure;


            // real params = [model.json, id, initial]
            var realParams = new ExpandoObject();

            realParams.Append(rw.parameters);
            if (rw.Id != null)
            {
                realParams.Set("Id", rw.Id);
            }
            realParams.Append(initialParams);

            IDataModel model = null;

            if (loadProc != null)
            {
                ExpandoObject prms2 = realParams;
                if (rw.indirect)
                {
                    // for indirect - @TenantId, @UserId and @Id only
                    prms2 = new ExpandoObject();
                    prms2.Set("Id", rw.Id);
                    if (realParams != null)
                    {
                        prms2.Set("UserId", realParams.Get <Int64>("UserId"));
                        prms2.Set("TenantId", realParams.Get <Int32>("TenantId"));
                    }
                }
                model = await _dbContext.LoadModelAsync(rw.CurrentSource, loadProc, prms2, rw.commandTimeout);

                if (rw.HasMerge)
                {
                    var mergeModel = await _dbContext.LoadModelAsync(rw.MergeSource, rw.MergeLoadProcedure, prms2, rw.commandTimeout);

                    model.Merge(mergeModel);
                }
                if (rw.copy)
                {
                    model.MakeCopy();
                }
                if (!String.IsNullOrEmpty(rw.Id) && !rw.copy)
                {
                    var me = model.MainElement;
                    if (me.Metadata != null)
                    {
                        var modelId = me.Id ?? String.Empty;
                        if (rw.Id != modelId.ToString())
                        {
                            throw new RequestModelException($"Element not found. Id={rw.Id}");
                        }
                    }
                }
            }
            if (rw.indirect)
            {
                rw = await LoadIndirect(rw, model, realParams);
            }
            if (model?.Root != null)
            {
                // side effect!
                rw.view       = model.Root.Resolve(rw.view);
                rw.viewMobile = model.Root.Resolve(rw.viewMobile);
                rw.template   = model.Root.Resolve(rw.template);
                rw.checkTypes = model.Root.Resolve(rw.checkTypes);
            }

            if (_userStateManager != null && model != null)
            {
                Int64 userId = realParams.Get <Int64>("UserId");
                if (_userStateManager.IsReadOnly(userId))
                {
                    model.SetReadOnly();
                }
            }
            dmv.Model       = model;
            dmv.RequestView = rw;
            return(dmv);
        }
Пример #2
0
        internal async Task <DataModelAndView> GetDataModelForView(RequestView rw, ExpandoObject loadPrms)
        {
            var dmv = new DataModelAndView()
            {
                RequestView = rw
            };
            String     loadProc = rw.LoadProcedure;
            IDataModel model    = null;

            if (rw.parameters != null && loadPrms == null)
            {
                loadPrms = rw.parameters;
            }
            if (loadPrms != null)
            {
                loadPrms.AppendIfNotExists(rw.parameters);
                if (rw.Id != null)
                {
                    loadPrms.Set("Id", rw.Id);
                }
            }
            if (loadProc != null)
            {
                ExpandoObject prms2 = loadPrms;
                if (rw.indirect)
                {
                    // for indirect - @TenantId, @UserId and @Id only
                    prms2 = new ExpandoObject();
                    prms2.Set("Id", rw.Id);
                    if (loadPrms != null)
                    {
                        prms2.Set("UserId", loadPrms.Get <Int64>("UserId"));
                        prms2.Set("TenantId", loadPrms.Get <Int32>("TenantId"));
                    }
                }
                model = await _dbContext.LoadModelAsync(rw.CurrentSource, loadProc, prms2);

                if (rw.copy)
                {
                    model.MakeCopy();
                }
                if (!String.IsNullOrEmpty(rw.Id) && !rw.copy)
                {
                    var me = model.MainElement;
                    if (me.Metadata != null)
                    {
                        var modelId = me.Id ?? String.Empty;
                        if (rw.Id != modelId.ToString())
                        {
                            throw new RequestModelException($"Element not found. Id={rw.Id}");
                        }
                    }
                }
            }
            if (rw.indirect)
            {
                rw = await LoadIndirect(rw, model, loadPrms);
            }
            if (model?.Root != null)
            {
                // side effect!
                rw.view     = model.Root.Resolve(rw.view);
                rw.template = model.Root.Resolve(rw.template);
            }

            if (_userStateManager != null && model != null)
            {
                Int64 userId = loadPrms.Get <Int64>("UserId");
                if (_userStateManager.IsReadOnly(userId))
                {
                    model.SetReadOnly();
                }
            }
            dmv.Model       = model;
            dmv.RequestView = rw;
            return(dmv);
        }
Пример #3
0
        public async Task CopyComplexModel()
        {
            IDataModel dm = await _dbContext.LoadModelAsync(null, "a2test.ComplexModel");

            dm.MakeCopy();
        }