Beispiel #1
0
        public IActionResult Post(CreateRecordModel model)
        {
            if (model.Data.IsEmpty())
            {
                return(JError("data is empty"));
            }
            Schema.Domain.Entity entityMeta = null;
            if (model.EntityId.HasValue && !model.EntityId.Value.Equals(Guid.Empty))
            {
                entityMeta = _entityFinder.FindById(model.EntityId.Value);
            }
            else if (model.EntityName.IsNotEmpty())
            {
                entityMeta = _entityFinder.FindByName(model.EntityName);
            }
            if (entityMeta == null)
            {
                return(NotFound());
            }
            var childAttributes = _attributeFinder.FindByEntityName(entityMeta.Name);

            if (model.Data.StartsWith("["))
            {
                var details = new List <Entity>();
                var items   = JArray.Parse(model.Data.UrlDecode());
                if (items.Count > 0)
                {
                    foreach (var c in items)
                    {
                        dynamic root   = JObject.Parse(c.ToString());
                        Entity  detail = new Entity(entityMeta.Name);
                        foreach (JProperty p in root)
                        {
                            var attr = childAttributes.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name));
                            if (attr != null && p.Value != null)
                            {
                                detail.SetAttributeValue(p.Name.ToString().ToLower(), detail.WrapAttributeValue(_entityFinder, attr, p.Value.ToString()));
                            }
                        }
                        details.Add(detail);
                    }
                }
                return(_dataCreater.CreateMany(details).CreateResult(T));
            }
            else
            {
                dynamic root   = JObject.Parse(model.Data.UrlDecode());
                Entity  detail = new Entity(entityMeta.Name);
                foreach (JProperty p in root)
                {
                    var attr = childAttributes.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name));
                    if (attr != null)
                    {
                        detail.SetAttributeValue(p.Name.ToString().ToLower(), detail.WrapAttributeValue(_entityFinder, attr, p.Value.ToString()));
                    }
                }
                var id = _dataCreater.Create(detail);
                return(CreateSuccess(new { id = id }));
            }
        }
Beispiel #2
0
        public IActionResult Retrieve(QueryExpression query)
        {
            if (query.EntityName.IsEmpty())
            {
                return(JError("entityname is not specified"));
            }
            var entity = _entityFinder.FindByName(query.EntityName);

            if (entity == null)
            {
                return(JError("entityname is not found"));
            }

            var result = _dataFinder.Retrieve(query);

            return(JOk(result));
        }
Beispiel #3
0
        public IActionResult Get([FromQuery] OrganizationModel model)
        {
            model.EntityMeta = _entityFinder.FindByName("organization");
            model.Attributes = _attributeFinder.FindByEntityId(model.EntityMeta.EntityId);
            FilterContainer <Organization.Domain.Organization> container = FilterContainerBuilder.Build <Organization.Domain.Organization>();

            if (model.Name.IsNotEmpty())
            {
                container.And(n => n.Name.Like(model.Name));
            }
            if (model.Name.IsNotEmpty())
            {
                container.And(n => n.Name.Like(model.Name));
            }
            if (model.StatusCode.HasValue)
            {
                container.And(n => n.StatusCode == model.StatusCode.Value);
            }
            if (model.GetAll)
            {
                var result = _organizationService.Query(x => x
                                                        .Where(container)
                                                        .Sort(n => n.OnFile(model.SortBy).ByDirection(model.SortDirection))
                                                        );
                model.Items      = result;
                model.TotalItems = result.Count;
            }
            else
            {
                if (!model.PageSizeBySeted)
                {
                    model.PageSize = CurrentUser.UserSettings.PagingLimit;
                }
                PagedList <Organization.Domain.Organization> result = _organizationService.QueryPaged(x => x
                                                                                                      .Page(model.Page, model.PageSize)
                                                                                                      .Where(container)
                                                                                                      .Sort(n => n.OnFile(model.SortBy).ByDirection(model.SortDirection))
                                                                                                      );

                model.Items      = result.Items;
                model.TotalItems = result.TotalItems;
            }
            return(JOk(model));
        }
Beispiel #4
0
        //public void BeginTransaction()
        //{
        //    _organizationDataProvider.BeginTransaction();
        //}

        //public void CommitTransaction()
        //{
        //    _organizationDataProvider.CommitTransaction();
        //}

        //public void RollBackTransaction()
        //{
        //    _organizationDataProvider.RollBackTransaction();
        //}

        #endregion transaction

        protected Schema.Domain.Entity GetEntityMetaData(string entityName)
        {
            Guard.NotEmpty(entityName, "entityName");
            var entityMetadata = _entityFinder.FindByName(entityName);

            if (entityMetadata == null)
            {
                throw new XmsException(string.Format(_loc["notfound_entityname"], entityName));
            }
            return(entityMetadata);
        }
Beispiel #5
0
        public IActionResult Get()
        {
            EditOrganizationModel model = new EditOrganizationModel();

            model.EntityMeta   = _entityFinder.FindByName("organization");
            model.Attributes   = _attributeFinder.FindByEntityId(model.EntityMeta.EntityId);
            model.StatusCode   = (int)RecordState.Enabled;
            model.LanguageList = _languageService.Query(n => n.Sort(s => s.SortAscending(f => f.UniqueId)));
            model.Datas        = new Entity("organization");
            return(JOk(model));
        }
Beispiel #6
0
        private void GetLinkMetaData(LinkEntity linkEntity, bool getEntities, bool getAttributes, bool getRelationShips)
        {
            //关联实体
            if (getEntities)
            {
                var entity = _entityFinder.FindByName(linkEntity.LinkToEntityName);
                _entityList.Add(entity);
            }
            //关联实体所有字段
            if (getAttributes)
            {
                var leAttributes = _attributeFinder.FindByEntityName(linkEntity.LinkToEntityName);
                if (leAttributes.NotEmpty())
                {
                    if (!linkEntity.Columns.AllColumns && linkEntity.Columns.Columns.NotEmpty())
                    {
                        leAttributes.RemoveAll(x => !linkEntity.Columns.Columns.Contains(x.Name, StringComparer.InvariantCultureIgnoreCase));
                    }
                    _attributeList.AddRange(leAttributes);
                }
            }
            //关系
            if (getRelationShips)
            {
                var rs = _relationShipFinder.Find(x => x.Name == linkEntity.EntityAlias);
                _relationShipList = new List <RelationShip>();
                _relationShipList.Add(rs);

                if (linkEntity.LinkEntities.NotEmpty())
                {
                    foreach (var le in linkEntity.LinkEntities)
                    {
                        GetLinkMetaData(le, getEntities, getAttributes, getRelationShips);
                    }
                }
            }
        }
Beispiel #7
0
        public IActionResult AttachmentsDialog(AttachmentsModel model, DialogModel dm)
        {
            if (!Arguments.HasValue(model.EntityId, model.ObjectId))
            {
                return(JError(T["parameter_error"]));
            }
            model.EntityMetaData     = _entityFinder.FindByName("attachment");
            model.AttributeMetaDatas = _attributeFinder.FindByEntityId(model.EntityMetaData.EntityId);
            var result = _attachmentFinder.QueryPaged(model.Page, model.PageSize, model.EntityId, model.ObjectId);

            model.Items             = result.Items;
            model.TotalItems        = result.TotalItems;
            ViewData["DialogModel"] = dm;
            return(View(model));
        }
Beispiel #8
0
        public IActionResult UserSettings()
        {
            UserSettingsModel model = new UserSettingsModel();

            model.EntityMeta           = _entityFinder.FindByName("SystemUserSettings");
            model.AttributesMeta       = _attributeFinder.FindByEntityId(model.EntityMeta.EntityId);
            model.Languages            = _languageService.Query(n => n.Sort(s => s.SortAscending(f => f.Name)));
            model.EntityDatas          = _dataFinder.RetrieveById("SystemUserSettings", CurrentUser.SystemUserId);
            model.SystemUserSettingsId = model.EntityDatas.GetIdValue();
            model.LanguageUniqueId     = model.EntityDatas.GetIntValue("languageuniqueid");
            model.PagingLimit          = model.EntityDatas.GetIntValue("paginglimit");
            model.CurrencyId           = model.EntityDatas.GetGuidValue("TransactionCurrencyId");
            model.EnabledNotification  = model.EntityDatas.GetBoolValue("EnabledNotification");
            return(View($"~/Views/User/{WebContext.ActionName}.cshtml", model));
        }
Beispiel #9
0
        public IActionResult Delete(DeleteEntityRecordModel model)
        {
            if (model.RecordId.IsEmpty())
            {
                return(NotSpecifiedRecord());
            }
            Entity entityMetadata = null;

            if (model.EntityName.IsNotEmpty())
            {
                entityMetadata = _entityFinder.FindByName(model.EntityName);
            }
            else
            {
                entityMetadata = _entityFinder.FindById(model.EntityId);
            }
            if (entityMetadata == null)
            {
                return(NotFound());
            }
            return(_dataDeleter.Delete(entityMetadata.Name, model.RecordId).DeleteResult(T));
        }
Beispiel #10
0
        public IActionResult Post(CreateEntityModel model)
        {
            if (ModelState.IsValid)
            {
                if (_entityFinder.FindByName(model.Name) != null)
                {
                    return(JError(T["name_already_exists"]));
                }
                model.Name = model.Name.Trim();
                var entity = new Schema.Domain.Entity();
                model.CopyTo(entity);
                entity.SolutionId     = _solutionId.Value;
                entity.IsCustomizable = true;
                entity.EntityId       = Guid.NewGuid();
                entity.CreatedBy      = CurrentUser.SystemUserId;
                entity.CreatedOn      = DateTime.Now;
                entity.OrganizationId = CurrentUser.OrganizationId;
                _entityCreater.Create(entity);

                return(CreateSuccess(new { id = entity.EntityId }));
            }
            return(CreateFailure(GetModelErrors()));
        }
Beispiel #11
0
        public IActionResult GetCompleteInfo(EntityFormModel args)
        {
            string nonePermissionFields = null, form = null, records = null;

            if (args.EntityId.Equals(Guid.Empty) && args.EntityName.IsEmpty())
            {
                return(NotFound());
            }
            var entity = args.EntityId.Equals(Guid.Empty) ? _entityFinder.FindByName(args.EntityName) : _entityFinder.FindById(args.EntityId);

            if (entity == null)
            {
                return(NotFound());
            }
            args.EntityId   = entity.EntityId;
            args.EntityName = entity.Name;
            EditRecordModel m = new EditRecordModel
            {
                EntityMetaData     = entity,
                EntityId           = args.EntityId,
                RelationShipName   = args.RelationShipName,
                ReferencedRecordId = args.ReferencedRecordId
            };

            if (args.RecordId.HasValue && !args.RecordId.Value.Equals(Guid.Empty))
            {
                var record = _dataFinder.RetrieveById(entity.Name, args.RecordId.Value);
                if (record == null || record.Count == 0)
                {
                    return(NotFound());
                }
                var fileAttributes = _attributeFinder.FindByEntityId(entity.EntityId).Where(n => n.DataFormat.IsCaseInsensitiveEqual("fileupload"));
                foreach (var item in fileAttributes)
                {
                    if (record.GetStringValue(item.Name).IsNotEmpty())
                    {
                        record[item.Name] = string.Empty;
                    }
                    else
                    {
                        record.Remove(item.Name);
                    }
                }
                m.Entity    = record;
                m.RecordId  = args.RecordId;
                m.FormState = FormState.Update;
                if (m.Entity.GetIntValue("statecode", -1) == 0)
                {
                    m.FormState = FormState.Disabled;
                    //model.ReadOnly = true;
                }
            }
            else if (args.CopyId.HasValue && !args.CopyId.Value.Equals(Guid.Empty))
            {
                var record = _dataFinder.RetrieveById(entity.Name, args.CopyId.Value);
                if (record == null || record.Count == 0)
                {
                    return(NotFound());
                }
                var fileAttributes = _attributeFinder.FindByEntityId(entity.EntityId).Where(n => n.DataFormat.IsCaseInsensitiveEqual("fileupload"));
                foreach (var item in fileAttributes)
                {
                    record.Remove(item.Name);
                }
                record.RemoveKeys(AttributeDefaults.SystemAttributes);
                m.Entity = record;
                //m.RecordId = model.RecordId;
                m.FormState = FormState.Create;
            }
            else
            {
                //ViewData["record"] = "{}";
                m.FormState = FormState.Create;
            }
            m.ReadOnly = args.ReadOnly;
            var        isCreate   = !args.RecordId.HasValue || args.RecordId.Value.Equals(Guid.Empty);
            SystemForm formEntity = null;

            //workflow
            if (!isCreate && m.EntityMetaData.WorkFlowEnabled && m.Entity.GetGuidValue("workflowid").Equals(Guid.Empty))
            {
                var processState = m.Entity.GetIntValue("processstate", -1);
                if (processState == (int)WorkFlowProcessState.Processing)// || processState == (int)WorkFlowProcessState.Passed)
                {
                    m.ReadOnly  = true;
                    m.FormState = FormState.ReadOnly;
                    var instances             = _workFlowInstanceService.Query(n => n.Take(1).Where(f => f.EntityId == m.EntityId.Value && f.ObjectId == m.RecordId.Value).Sort(s => s.SortDescending(f => f.CreatedOn)));
                    WorkFlowInstance instance = null;
                    if (instances.NotEmpty())
                    {
                        instance = instances.First();
                    }
                    if (instance != null)
                    {
                        var processInfo = _workFlowProcessFinder.GetCurrentStep(instance.WorkFlowInstanceId, CurrentUser.SystemUserId);
                        if (processInfo != null)
                        {
                            if (!processInfo.FormId.Equals(Guid.Empty))
                            {
                                formEntity = _systemFormFinder.FindById(processInfo.FormId);
                            }
                        }
                    }
                }
                m.WorkFlowProcessState = processState;
            }
            if (formEntity == null)
            {
                if (args.FormId.HasValue && !args.FormId.Value.Equals(Guid.Empty))
                {
                    formEntity = _systemFormFinder.FindById(args.FormId.Value);
                    if (formEntity.StateCode != RecordState.Enabled)
                    {
                        formEntity = null;
                    }
                }
                else
                {
                    //获取实体默认表单
                    formEntity = _systemFormFinder.FindEntityDefaultForm(args.EntityId);
                }
            }
            if (formEntity == null)
            {
                return(JError(T["notfound_defaultform"]));
            }
            m.FormInfo = formEntity;
            m.FormId   = formEntity.SystemFormId;
            FormBuilder formBuilder = new FormBuilder(formEntity.FormConfig);

            _formService.Init(formEntity);
            //表单可用状态
            if (!isCreate && m.FormState != FormState.Disabled && formBuilder.Form.FormRules.NotEmpty())
            {
                if (_systemFormStatusSetter.IsDisabled(formBuilder.Form.FormRules, m.Entity))
                {
                    m.FormState = FormState.Disabled;
                }
            }
            //获取所有字段信息
            m.AttributeList = _formService.AttributeMetaDatas;
            //获取字段权限
            if (!CurrentUser.IsSuperAdmin && m.AttributeList.Count(n => n.AuthorizationEnabled) > 0)
            {
                var securityFields = m.AttributeList.Where(n => n.AuthorizationEnabled).Select(f => f.AttributeId)?.ToList();
                if (securityFields.NotEmpty())
                {
                    //无权限的字段
                    var noneRead = _systemUserPermissionService.GetNoneReadFields(CurrentUser.SystemUserId, securityFields);
                    var noneEdit = _systemUserPermissionService.GetNoneEditFields(CurrentUser.SystemUserId, securityFields);
                    //移除无读取权限的字段内容
                    if (m.Entity.NotEmpty())
                    {
                        foreach (var item in noneRead)
                        {
                            m.Entity.Remove(m.AttributeList.Find(n => n.AttributeId == item).Name);
                        }
                    }
                    var obj = new { noneread = noneRead, noneedit = noneEdit };
                    nonePermissionFields = obj.SerializeToJson();
                }
            }
            else
            {
                nonePermissionFields = "[]";
            }
            var _form = formBuilder.Form;

            m.Form = _form;
            form   = _formService.Form.SerializeToJson(false);
            //buttons
            var buttons = _ribbonbuttonFinder.Find(m.EntityId.Value, RibbonButtonArea.Form);

            if (formEntity.IsCustomButton && formEntity.CustomButtons.IsNotEmpty())
            {
                List <Guid> buttonid = new List <Guid>();
                buttonid = buttonid.DeserializeFromJson(formEntity.CustomButtons);
                buttons.RemoveAll(x => !buttonid.Contains(x.RibbonButtonId));
            }
            if (buttons.NotEmpty())
            {
                buttons         = buttons.OrderBy(x => x.DisplayOrder).ToList();
                m.RibbonButtons = buttons;
                _ribbonButtonStatusSetter.Set(m.RibbonButtons, m.FormState, m.Entity);
            }
            if (isCreate)
            {
                var rep = _roleObjectAccessEntityPermissionService.FindUserPermission(m.EntityMetaData.Name, CurrentUser.LoginName, AccessRightValue.Create);
                m.HasBasePermission = rep != null && rep.AccessRightsMask != EntityPermissionDepth.None;
            }
            else
            {
                var rep = _roleObjectAccessEntityPermissionService.FindUserPermission(m.EntityMetaData.Name, CurrentUser.LoginName, AccessRightValue.Update);
                m.HasBasePermission = rep != null && rep.AccessRightsMask != EntityPermissionDepth.None;
            }
            m.SnRule = _serialNumberRuleFinder.FindByEntityId(args.EntityId);
            if (m.SnRule != null && m.Entity.NotEmpty() && args.CopyId.HasValue)
            {
                m.Entity.SetAttributeValue(m.SnRule.AttributeName, null);
            }
            records                  = m.Entity.SerializeToJson();
            m.StageId                = args.StageId;
            m.BusinessFlowId         = args.BusinessFlowId;
            m.BusinessFlowInstanceId = args.BusinessFlowInstanceId;

            return(JOk(new { EditRecord = m, NonePermissionFields = nonePermissionFields, Form = form, Record = records }));
        }
Beispiel #12
0
        public IActionResult SaveChilds(SaveChildDataModel model)
        {
            if (model.Child.IsEmpty())
            {
                return(JError("data is empty"));
            }
            var childs = JArray.Parse(model.Child.UrlDecode());

            if (childs.Count > 0)
            {
                var entityMeta = _entityFinder.FindByName(model.EntityName);
                if (entityMeta == null)
                {
                    return(NotFound());
                }
                var           entityid      = entityMeta.EntityId;
                List <Entity> childEntities = new List <Entity>();
                List <string> entityNames   = new List <string>();
                foreach (var c in childs)
                {
                    dynamic root = JObject.Parse(c.ToString());
                    string  name = root.name, relationshipname = root.relationshipname, refname = string.Empty;
                    if (!entityNames.Exists(n => n.IsCaseInsensitiveEqual(name)))
                    {
                        entityNames.Add(name);
                    }

                    var data            = root.data;
                    var childAttributes = _attributeFinder.FindByEntityName(name);
                    if (relationshipname.IsNotEmpty())
                    {
                        var relationShipMetas = _relationShipFinder.FindByName(relationshipname);
                        if (null != relationShipMetas && relationShipMetas.ReferencedEntityId == entityid)
                        {
                            refname = relationShipMetas.ReferencingAttributeName;
                        }
                    }
                    Entity detail = new Entity(name);
                    foreach (JProperty p in data)
                    {
                        var attr = childAttributes.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name));
                        if (attr != null && p.Value != null)
                        {
                            detail.SetAttributeValue(p.Name.ToString().ToLower(), detail.WrapAttributeValue(_entityFinder, attr, p.Value.ToString()));
                        }
                    }
                    //关联主记录ID
                    if (refname.IsNotEmpty())
                    {
                        detail.SetAttributeValue(refname, new EntityReference(entityMeta.Name, model.ParentId));
                    }
                    childEntities.Add(detail);
                }
                //批量创建记录
                if (childEntities.NotEmpty())
                {
                    foreach (var item in entityNames)
                    {
                        var items           = childEntities.Where(n => n.Name.IsCaseInsensitiveEqual(item)).ToList();
                        var creatingRecords = items.Where(n => n.Name.IsCaseInsensitiveEqual(item) && n.GetIdValue().Equals(Guid.Empty)).ToList();
                        if (creatingRecords.NotEmpty())
                        {
                            _dataCreater.CreateMany(creatingRecords);
                        }
                        if (creatingRecords.Count < childEntities.Count)
                        {
                            var updatingRecords = items.Where(n => n.Name.IsCaseInsensitiveEqual(item) && !n.GetIdValue().Equals(Guid.Empty)).ToList();
                            foreach (var updItem in updatingRecords)
                            {
                                _dataUpdater.Update(updItem);
                            }
                        }
                    }
                }
            }
            return(SaveSuccess());
        }
Beispiel #13
0
        public IActionResult Get(string name)
        {
            var result = _entityFinder.FindByName(name);

            return(JOk(result));
        }
Beispiel #14
0
        public IActionResult Post(DataUpdateModel model)
        {
            Schema.Domain.Entity entityMeta = null;
            if (model.EntityId.HasValue && !model.EntityId.Value.Equals(Guid.Empty))
            {
                entityMeta = _entityFinder.FindById(model.EntityId.Value);
            }
            else if (model.EntityName.IsNotEmpty())
            {
                entityMeta = _entityFinder.FindByName(model.EntityName);
            }
            if (entityMeta == null)
            {
                return(NotFound());
            }
            var childAttributes = _attributeFinder.FindByEntityName(entityMeta.Name);
            var primaryAttr     = childAttributes.Find(n => n.TypeIsPrimaryKey());

            if (model.Data.StartsWith("["))
            {
                //var details = new List<Entity>();
                var items = JArray.Parse(model.Data.UrlDecode());
                if (items.Count > 0)
                {
                    foreach (var c in items)
                    {
                        dynamic root   = JObject.Parse(c.ToString());
                        Entity  detail = new Entity(entityMeta.Name);
                        foreach (JProperty p in root)
                        {
                            if (p.Name.IsCaseInsensitiveEqual("id"))
                            {
                                detail.SetIdValue(Guid.Parse(p.Value.ToString()), primaryAttr.Name);
                            }
                            else
                            {
                                var attr = childAttributes.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name));
                                if (attr != null)
                                {
                                    detail.SetAttributeValue(p.Name.ToString().ToLower(), detail.WrapAttributeValue(_entityFinder, attr, p.Value.ToString()));
                                }
                            }
                        }
                        //details.Add(detail);
                        _dataUpdater.Update(detail);
                    }
                }
                //_organizationServiceProxy.UpdateMany(details);
                return(UpdateSuccess());
            }
            else
            {
                Entity  detail = new Entity(entityMeta.Name);
                dynamic root   = JObject.Parse(model.Data.UrlDecode());
                foreach (JProperty p in root)
                {
                    if (p.Name.IsCaseInsensitiveEqual("id"))
                    {
                        detail.SetIdValue(Guid.Parse(p.Value.ToString()), primaryAttr.Name);
                    }
                    else
                    {
                        var attr = childAttributes.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name));
                        if (attr != null)
                        {
                            detail.SetAttributeValue(p.Name.ToString().ToLower(), detail.WrapAttributeValue(_entityFinder, attr, p.Value.ToString()));
                        }
                    }
                }
                _dataUpdater.Update(detail);
            }
            return(UpdateSuccess());
        }