Ejemplo n.º 1
0
        public IActionResult AddMembers(Guid teamId, Guid[] userid)
        {
            if (userid.IsEmpty())
            {
                return(JError(T["notspecified_record"]));
            }
            var query = new QueryExpression("TeamMembership", CurrentUser.UserSettings.LanguageId);

            query.ColumnSet.AddColumns("systemuserid");
            query.Criteria.AddCondition("teamid", ConditionOperator.Equal, teamId);
            var members     = _dataFinder.RetrieveAll(query);
            var addEntities = new List <Entity>();

            foreach (var item in userid)
            {
                if (!members.Any(n => n.GetGuidValue("systemuserid") == item))
                {
                    Entity entity = new Entity("TeamMembership");
                    entity.SetAttributeValue("teamid", teamId);
                    entity.SetAttributeValue("systemuserid", item);
                    addEntities.Add(entity);
                }
            }
            if (addEntities.NotEmpty())
            {
                _dataCreater.CreateMany(addEntities);
            }
            return(JOk(T["added_success"]));
        }
Ejemplo n.º 2
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 }));
            }
        }
Ejemplo n.º 3
0
        public Guid Create(AggregateRoot aggregateRoot, Guid?systemFormId = null, bool ignorePermissions = false)
        {
            AggregateRootMetaData aggRootMetaData = GetAggregateRootMetaData(aggregateRoot, systemFormId);
            var thisId = Guid.Empty;

            try
            {
                _organizationDataProvider.BeginTransaction();
                InternalOnCreate(aggregateRoot, OperationStage.PreOperation, aggRootMetaData);

                //关联Id
                thisId = Guid.NewGuid();

                foreach (var c in aggregateRoot.ChildEntities)
                {
                    string name = c.Name, relationshipname = c.Relationshipname, refname = string.Empty;
                    if (relationshipname.IsNotEmpty())
                    {
                        var relationShipMetas = _relationShipFinder.FindByName(c.Relationshipname);
                        if (null != relationShipMetas && relationShipMetas.ReferencedEntityId == c.Entityid)
                        {
                            refname = relationShipMetas.ReferencingAttributeName;
                        }
                        if (refname.IsNotEmpty())
                        {
                            c.Entity.SetAttributeValue(refname, new EntityReference(aggregateRoot.MainEntity.Name, thisId));
                        }
                    }
                }

                var childEntities = aggregateRoot.ChildEntities.Select(x => x.Entity).ToList();
                var entityNames   = childEntities.Select(n => n.Name).Distinct().ToList();
                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);
                    }
                }
                aggregateRoot.MainEntity.SetIdValue(thisId);
                _dataCreater.Create(aggregateRoot.MainEntity);

                InternalOnCreate(aggregateRoot, OperationStage.PostOperation, aggRootMetaData);

                _organizationDataProvider.CommitTransaction();
            }
            catch (Exception e)
            {
                _organizationDataProvider.RollBackTransaction();
                OnException(e);
            }
            return(thisId);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 创建多条记录
        /// </summary>
        /// <param name="entityId"></param>
        /// <param name="objectId"></param>
        /// <param name="files"></param>
        /// <returns></returns>
        public virtual async Task <List <Entity> > CreateManyAsync(Guid entityId, Guid objectId, List <IFormFile> files, bool autoFileName = true)
        {
            //附件
            List <Entity> attachments = new List <Entity>();

            if (files.NotEmpty())
            {
                for (int i = 0; i < files.Count; i++)
                {
                    var file = files[i];
                    if (file.Length > 0)
                    {
                        string dir      = _webHelper.MapPath(Path, true);
                        Guid   id       = Guid.NewGuid();
                        string fileName = file.Name + System.IO.Path.GetExtension(file.FileName);
                        if (autoFileName)
                        {
                            fileName = id.ToString() + System.IO.Path.GetExtension(file.FileName);
                        }
                        string savePath = dir + fileName;
                        await file.SaveAs(savePath, _settingFinder, _webHelper).ConfigureAwait(false);

                        Entity ent = new Entity(EntityName)
                                     .SetIdValue(id)
                                     .SetAttributeValue("name", file.FileName)
                                     .SetAttributeValue("filesize", file.Length)
                                     .SetAttributeValue("mimetype", file.ContentType)
                                     .SetAttributeValue("cdnpath", Path + fileName)
                                     .SetAttributeValue("entityid", entityId)
                                     .SetAttributeValue("objectid", objectId);
                        attachments.Add(ent);
                    }
                }
            }
            //保存附件
            if (attachments.Count > 0)
            {
                _dataCreater.CreateMany(attachments);
                return(attachments);//.Select(x=>x["cdnpath"].ToString()).ToList();
            }
            return(null);
        }
Ejemplo n.º 5
0
 public IActionResult AssignRolesToTeam(Guid[] teamId, Guid[] roleId)
 {
     if (!Arguments.HasValue(teamId) || !Arguments.HasValue(roleId))
     {
         return(NotSpecifiedRecord());
     }
     foreach (var tid in teamId)
     {
         List <Guid> needDeleted = new List <Guid>();
         var         query       = new QueryExpression("TeamRoles", CurrentUser.UserSettings.LanguageId);
         query.ColumnSet.AddColumns("teamid", "roleid");
         query.Criteria.AddCondition("teamid", ConditionOperator.Equal, tid);
         var datas       = _dataFinder.RetrieveAll(query);
         var addEntities = new List <Entity>();
         foreach (var item in roleId)
         {
             if (!datas.Any(n => n.GetGuidValue("roleid") == item))
             {
                 Entity entity = new Entity("TeamRoles");
                 entity.SetAttributeValue("teamid", teamId);
                 entity.SetAttributeValue("roleid", item);
                 addEntities.Add(entity);
             }
         }
         var b = datas.Where(n => !roleId.Contains(n.GetGuidValue("roleid"))).Select(n => n.GetGuidValue("teamroleid")).ToList();
         needDeleted.AddRange(b);
         if (needDeleted.NotEmpty())
         {
             //delete
             _dataDeleter.Delete("teamroles", needDeleted);
         }
         if (addEntities.NotEmpty())
         {
             _dataCreater.CreateMany(addEntities);
         }
     }
     return(SaveSuccess());
 }
Ejemplo n.º 6
0
        public IActionResult Post(SaveDataModel model)
        {
            if (model.EntityId.Equals(Guid.Empty))
            {
                return(NotFound());
            }
            var entityMetaData = _entityFinder.FindById(model.EntityId);

            if (entityMetaData == null)
            {
                return(NotFound());
            }
            var  attributeMetaDatas = _attributeFinder.FindByEntityId(model.EntityId);
            bool isNew  = !(model.RecordId.HasValue && !model.RecordId.Value.Equals(Guid.Empty));
            var  thisId = Guid.Empty;

            try
            {
                Core.Data.Entity entity   = new Core.Data.Entity(entityMetaData.Name);
                dynamic          headData = JObject.Parse(model.Data);
                foreach (JProperty p in headData)
                {
                    var attr = attributeMetaDatas.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name));
                    if (attr != null && p.Value != null)
                    {
                        entity.SetAttributeValue(p.Name.ToString().ToLower(), entity.WrapAttributeValue(_entityFinder, attr, p.Value.ToString()));
                    }
                }
                if (isNew)
                {
                    if (model.RelationShipName.IsNotEmpty() && model.ReferencedRecordId.HasValue)//如果存在关联关系
                    {
                        var relationShipMetas = _relationShipFinder.FindByName(model.RelationShipName);
                        if (null != relationShipMetas && relationShipMetas.ReferencingEntityId == model.EntityId && entity.GetStringValue(relationShipMetas.ReferencingAttributeName).IsEmpty())
                        {
                            //设置当前记录关联字段的值
                            entity.SetAttributeValue(relationShipMetas.ReferencingAttributeName, new EntityReference(relationShipMetas.ReferencedEntityName, model.ReferencedRecordId.Value));
                        }
                    }
                    if (!model.StageId.Equals(Guid.Empty))//业务流程的阶段
                    {
                        entity.SetAttributeValue("StageId", model.StageId);
                    }
                    thisId = _dataCreater.Create(entity);
                    if (!model.StageId.Equals(Guid.Empty))//业务流程的阶段
                    {
                        _businessProcessFlowInstanceUpdater.UpdateForward(model.BusinessFlowId, model.BusinessFlowInstanceId, model.StageId, thisId);
                    }
                }
                else
                {
                    thisId = model.RecordId.Value;
                    entity.SetIdValue(model.RecordId.Value);
                    _dataUpdater.Update(entity);
                }
                //单据体
                if (model.Child.IsNotEmpty())
                {
                    var childs = JArray.Parse(model.Child.UrlDecode());
                    if (childs.Count > 0)
                    {
                        List <Core.Data.Entity> childEntities = new List <Core.Data.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 == model.EntityId)
                                {
                                    refname = relationShipMetas.ReferencingAttributeName;
                                }
                            }
                            Core.Data.Entity detail = new Core.Data.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(entityMetaData.Name, thisId));
                            }
                            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 (!isNew)
                                {
                                    foreach (var updItem in items.Where(n => n.Name.IsCaseInsensitiveEqual(item) && !n.GetIdValue().Equals(Guid.Empty)))
                                    {
                                        _dataUpdater.Update(updItem);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(JError(ex.InnerException != null ? ex.InnerException.Message : ex.Message));
            }
            if (isNew)
            {
                return(CreateSuccess(new { id = thisId }));
            }
            return(UpdateSuccess(new { id = thisId }));
        }