Esempio n. 1
0
        public IActionResult EditOptionSet(Guid id)
        {
            EditOptionSetModel model = new EditOptionSetModel();

            if (!id.Equals(Guid.Empty))
            {
                var entity = _optionSetFinder.FindById(id);
                if (entity != null)
                {
                    entity.CopyTo(model);
                    model.Details = entity.Items.OrderBy(x => x.DisplayOrder).ToList();
                    return(View(model));
                }
            }
            return(NotFound());
        }
Esempio n. 2
0
        public IActionResult Post(EditOptionSetModel model)
        {
            if (ModelState.IsValid)
            {
                bool hasDupName = model.OptionSetName.GroupBy(x => x).Where(g => g.Count() > 1).Count() > 0;
                if (hasDupName)
                {
                    return(JError(T["validation_name_duplicated"]));
                }
                bool hasDupVal = model.OptionSetValue.GroupBy(x => x).Where(g => g.Count() > 1).Count() > 0;
                if (hasDupVal)
                {
                    return(JError(T["validation_value_duplicated"]));
                }
                var entity  = _optionSetFinder.FindById(model.OptionSetId);
                var details = entity.Items;
                model.CopyTo(entity);
                entity.IsPublic = true;
                _optionSetUpdater.Update(entity);
                int i = 0;
                foreach (var item in model.OptionSetName)
                {
                    if (item.IsEmpty())
                    {
                        continue;
                    }
                    Guid detailid = model.DetailId[i];
                    Schema.Domain.OptionSetDetail osd = new Schema.Domain.OptionSetDetail();
                    osd.OptionSetId  = entity.OptionSetId;
                    osd.Name         = item;
                    osd.Value        = model.OptionSetValue[i];
                    osd.IsSelected   = model.IsSelectedOption[i];
                    osd.DisplayOrder = i;
                    if (detailid.Equals(Guid.Empty))
                    {
                        osd.OptionSetDetailId = Guid.NewGuid();
                        _optionSetDetailCreater.Create(osd);
                    }
                    else
                    {
                        osd.OptionSetDetailId = detailid;
                        _optionSetDetailUpdater.Update(osd);
                        details.Remove(details.Find(n => n.OptionSetDetailId == detailid));
                    }

                    i++;
                }
                //delete lost detail
                if (details.NotEmpty())
                {
                    var lostid = details.Select(n => n.OptionSetDetailId).ToList();
                    _optionSetDetailDeleter.DeleteById(lostid.ToArray());
                }

                return(UpdateSuccess(new { id = entity.OptionSetId }));
            }
            return(UpdateFailure(GetModelErrors()));
        }
Esempio n. 3
0
        public IActionResult EditAttribute(Guid id)
        {
            if (id.Equals(Guid.Empty))
            {
                return(NotFound());
            }
            EditAttributeModel model = new EditAttributeModel();
            var entity = _attributeFinder.FindById(id);

            if (entity == null)
            {
                return(NotFound());
            }
            model.Entity = _entityFinder.FindById(entity.EntityId);
            if (model.Entity != null)
            {
                entity.CopyTo(model);
                if (entity.OptionSetId.HasValue)
                {
                    entity.OptionSet       = _optionSetFinder.FindById(entity.OptionSetId.Value);
                    entity.OptionSet.Items = _optionSetDetailFinder.Query(n => n.Where(w => w.OptionSetId == entity.OptionSetId.Value).Sort(s => s.SortAscending(f => f.DisplayOrder)));

                    model.IsCommonOptionSet = entity.OptionSet.IsPublic;
                }
                if (entity.TypeIsBit() || entity.TypeIsState())
                {
                    entity.PickLists = _stringMapFinder.Query(n => n.Where(w => w.AttributeId == entity.AttributeId));
                }
                model.Attribute = entity;
                if (model.SummaryExpression.IsNotEmpty())
                {
                    model.AaExp = new AttributeAggregateExpression().DeserializeFromJson(model.SummaryExpression);
                }
                else
                {
                    model.AaExp = new AttributeAggregateExpression();
                }

                return(View(model));
            }
            else
            {
                return(NotFound());
            }
        }
Esempio n. 4
0
        public bool Update(Domain.Attribute entity)
        {
            var result = true;

            using (UnitOfWork.Build(_attributeRepository.DbContext))
            {
                result = _attributeRepository.Update(entity);
                if (entity.OptionSetId.HasValue && entity.OptionSet != null && !entity.OptionSet.IsPublic)
                {
                    var details = _optionSetDetailFinder.Query(n => n.Select(f => f.OptionSetDetailId).Where(f => f.OptionSetId == entity.OptionSetId.Value));
                    foreach (var item in entity.OptionSet.Items)
                    {
                        if (item.OptionSetDetailId.Equals(Guid.Empty))
                        {
                            item.OptionSetDetailId = Guid.NewGuid();
                            result = _optionSetDetailCreater.Create(item);
                        }
                        else
                        {
                            result = _optionSetDetailUpdater.Update(item);
                        }
                    }
                    //delete lost
                    var ids    = entity.OptionSet.Items.Select(n => n.OptionSetDetailId);
                    var lostid = details.Select(n => n.OptionSetDetailId).Except(ids).ToList();
                    if (lostid.NotEmpty())
                    {
                        result = _optionSetDetailDeleter.DeleteById(lostid.ToArray());
                    }
                }
                if (entity.PickLists.NotEmpty())//bit
                {
                    foreach (var item in entity.PickLists)
                    {
                        if (item.StringMapId.Equals(Guid.Empty))
                        {
                            result = _stringMapCreater.Create(item);
                        }
                        else
                        {
                            result = _stringMapUpdater.Update(item);
                        }
                    }
                }
                //localization
                _localizedLabelService.Update(entity.LocalizedName.IfEmpty(""), "LocalizedName", entity.AttributeId, this._appContext.BaseLanguage);
                _localizedLabelService.Update(entity.Description.IfEmpty(""), "Description", entity.AttributeId, this._appContext.BaseLanguage);
                //set to cache
                var optionSetEntity = _optionSetFinder.FindById(entity.OptionSet.OptionSetId);
                _cacheService.SetEntity(entity);
                _cacheServiceOption.RemoveEntity(optionSetEntity);
            }
            return(result);
        }
Esempio n. 5
0
 private void SetAttributeItems(Schema.Domain.Attribute attr)
 {
     if ((attr.TypeIsPickList() || attr.TypeIsStatus()))// && attr.OptionSet == null)
     {
         var os = _optionSetFinder.FindById(attr.OptionSetId.Value);
         attr.OptionSet = os;
     }
     else if ((attr.TypeIsBit() ||
               attr.TypeIsState()
               ))// && attr.PickLists.IsEmpty())
     {
         attr.PickLists = _stringMapFinder.Query(n => n.Where(w => w.AttributeId == attr.AttributeId).Sort(s => s.SortAscending(f => f.DisplayOrder)));
     }
 }
Esempio n. 6
0
 public bool Import(Guid solutionId, IList <Domain.OptionSet> optionSets)
 {
     if (optionSets.NotEmpty())
     {
         foreach (var item in optionSets)
         {
             foreach (var d in item.Items)
             {
                 d.OptionSetId = item.OptionSetId;
             }
             var entity = _optionSetFinder.FindById(item.OptionSetId);
             if (entity != null)
             {
                 item.CreatedBy      = _appContext.GetFeature <ICurrentUser>().SystemUserId;
                 item.CreatedOn      = DateTime.Now;
                 item.SolutionId     = solutionId;
                 item.OrganizationId = _appContext.OrganizationId;
                 _optionSetUpdater.Update(item);
                 //_optionSetDetailService.DeleteByParentId(entity.OptionSetId);
                 //_optionSetDetailService.CreateMany(item.Items);
                 foreach (var d in item.Items)
                 {
                     var dd = _optionSetDetailFinder.Find(x => x.OptionSetId == item.OptionSetId && x.OptionSetDetailId == d.OptionSetDetailId);
                     if (dd != null)
                     {
                         dd.Name  = d.Name;
                         dd.Value = d.Value;
                         _optionSetDetailUpdater.Update(dd);
                     }
                     else
                     {
                         d.OptionSetId = item.OptionSetId;
                         _optionSetDetailCreater.Create(d);
                     }
                 }
             }
             else
             {
                 item.CreatedBy      = _appContext.GetFeature <ICurrentUser>().SystemUserId;
                 item.CreatedOn      = DateTime.Now;
                 item.SolutionId     = solutionId;
                 item.OrganizationId = _appContext.GetFeature <ICurrentUser>().OrganizationId;
                 _optionSetCreater.Create(item);
                 _optionSetDetailCreater.CreateMany(item.Items);
             }
         }
     }
     return(true);
 }
Esempio n. 7
0
        /// <summary>
        /// 过滤条件对话框
        /// </summary>
        /// <returns></returns>
        public IActionResult FilterDialog([FromBody] FilterModel model, DialogModel dm)
        {
            ViewData["DialogModel"] = dm;
            if (model.Field.IsNotEmpty())
            {
                //如果是关联表字段
                if (model.Field.IndexOf('.') > 0)
                {
                    var relationshipName = model.Field.Split('.')[0];
                    var field            = model.Field.Split('.')[1];
                    //根据关系查询目标实体ID
                    var relationship = _relationShipFinder.FindByName(relationshipName);
                    model.AttributeMeta    = _attributeFinder.Find(relationship.ReferencedEntityId, field);
                    model.RelationShipMeta = relationship;
                }
                else
                {
                    model.AttributeMeta = _attributeFinder.Find(model.EntityId, model.Field);
                }
                if (model.AttributeMeta == null)
                {
                    return(NotFound());
                }
                if (model.AttributeMeta.AttributeTypeName.IsCaseInsensitiveEqual(AttributeTypeIds.PICKLIST))
                {
                    model.AttributeMeta.OptionSet = _optionSetFinder.FindById(model.AttributeMeta.OptionSetId.Value);
                }
                if (model.AttributeMeta.AttributeTypeName.IsCaseInsensitiveEqual(AttributeTypeIds.BIT) ||
                    model.AttributeMeta.AttributeTypeName.IsCaseInsensitiveEqual(AttributeTypeIds.STATE))
                {
                    model.AttributeMeta.PickLists = _stringMapFinder.Query(n => n.Where(w => w.AttributeId == model.AttributeMeta.AttributeId));
                }
            }

            return(View(model));
        }
Esempio n. 8
0
        public IActionResult KanbanView([FromBody, FromQuery] KanbanGridModel model)
        {
            if (model.AggregateField.IsEmpty() || model.GroupField.IsEmpty())
            {
                return(JError("请指定统计字段及分组字段"));
            }
            QueryView.Domain.QueryView queryView = null;
            if (model.QueryId.HasValue && !model.QueryId.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindById(model.QueryId.Value);
            }
            if (queryView == null)
            {
                return(NotFound());
            }
            if (!queryView.IsDefault && queryView.AuthorizationEnabled)
            {
                if (!_roleObjectAccessService.Exists(queryView.QueryViewId, QueryViewDefaults.ModuleName, CurrentUser.Roles.Select(n => n.RoleId).ToArray()))
                {
                    return(Unauthorized());
                }
            }
            model.QueryView  = queryView;
            model.EntityId   = queryView.EntityId;
            model.QueryId    = queryView.QueryViewId;
            model.EntityName = _entityFinder.FindById(model.EntityId.Value).Name;
            var attributes = new List <Schema.Domain.Attribute>();
            var aggAttr    = _attributeFinder.Find(model.EntityId.Value, model.AggregateField);

            attributes.Add(aggAttr);
            var queryExp = new QueryExpression();

            queryExp = queryExp.DeserializeFromJson(queryView.FetchConfig);
            var orderExp = new OrderExpression("createdon", OrderType.Descending);

            queryExp.Orders.Add(orderExp);
            Dictionary <string, AggregateType> attributeAggs = new Dictionary <string, AggregateType>();

            if (aggAttr.TypeIsInt() || aggAttr.TypeIsFloat() || aggAttr.TypeIsDecimal() || aggAttr.TypeIsMoney())
            {
                attributeAggs.Add(model.AggregateField, AggregateType.Sum);
                model.AggType = AggregateType.Sum;
            }
            else
            {
                attributeAggs.Add(model.AggregateField, AggregateType.Count);
                model.AggType = AggregateType.Count;
            }
            var datas = _aggregateService.Execute(queryExp, attributeAggs, new List <string>()
            {
                model.GroupField
            });

            model.Items = datas;
            queryExp.ColumnSet.Columns.Clear();
            queryExp.ColumnSet.AddColumns("createdon", model.AggregateField, model.GroupField, "ownerid");
            model.GroupingDatas = _aggregateService.GroupingTop(model.GroupingTop, model.GroupField, queryExp, orderExp);
            var groupAttr = _attributeFinder.Find(model.EntityId.Value, model.GroupField);

            groupAttr.OptionSet = _optionSetFinder.FindById(groupAttr.OptionSetId.Value);
            attributes.Add(groupAttr);
            model.AttributeList = attributes;
            return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model));
        }
Esempio n. 9
0
        public IActionResult Post(EditAttributeModel model)
        {
            if (ModelState.IsValid)
            {
                var attrInfo = _attributeFinder.FindById(model.AttributeId.Value);
                if (attrInfo == null)
                {
                    return(NotFound());
                }
                //model.CopyTo(attrInfo);
                //attrInfo.IsCustomizable = true;
                attrInfo.LocalizedName        = model.LocalizedName;
                attrInfo.LogEnabled           = model.IsLoged;
                attrInfo.IsRequired           = model.IsRequired;
                attrInfo.AuthorizationEnabled = model.IsSecured;
                attrInfo.Description          = model.Description;
                attrInfo.ValueType            = model.ValueType;
                var attrTypeName = attrInfo.AttributeTypeName;
                if (attrTypeName == "state")
                {
                    attrTypeName = "bit";
                }
                else if (attrTypeName == "status")
                {
                    attrTypeName = "picklist";
                }

                switch (attrTypeName)
                {
                case AttributeTypeIds.NVARCHAR:
                    attrInfo.MaxLength    = model.MaxLength.Value;
                    attrInfo.DataFormat   = model.TextFormat;
                    attrInfo.DefaultValue = model.DefaultValue;
                    if (model.ValueType == 2)
                    {
                        attrInfo.FormulaExpression = model.FormulaExpression;
                    }
                    break;

                case AttributeTypeIds.NTEXT:
                    attrInfo.DataFormat = model.NTextFormat;
                    break;

                case AttributeTypeIds.INT:
                    attrInfo.MinValue     = model.IntMinValue.Value <= int.MinValue ? int.MinValue + 2 : model.IntMinValue.Value;
                    attrInfo.MaxValue     = model.IntMaxValue.Value >= int.MaxValue ? int.MaxValue - 2 : model.IntMaxValue.Value;
                    attrInfo.DefaultValue = model.DefaultValue;
                    if (model.ValueType == 2)
                    {
                        attrInfo.FormulaExpression = model.FormulaExpression;
                    }
                    else if (model.ValueType == 3)
                    {
                        attrInfo.SummaryEntityId   = model.SummaryEntityId;
                        attrInfo.SummaryExpression = model.SummaryExpression;
                    }
                    break;

                case AttributeTypeIds.FLOAT:
                    attrInfo.Precision    = model.FloatPrecision.Value;
                    attrInfo.MinValue     = model.FloatMinValue.Value <= float.MinValue ? float.MinValue + 2 : model.FloatMinValue.Value;
                    attrInfo.MaxValue     = model.FloatMaxValue.Value >= float.MaxValue ? float.MaxValue - 2 : model.FloatMaxValue.Value;
                    attrInfo.DefaultValue = model.DefaultValue;
                    if (model.ValueType == 2)
                    {
                        attrInfo.FormulaExpression = model.FormulaExpression;
                    }
                    else if (model.ValueType == 3)
                    {
                        attrInfo.SummaryEntityId   = model.SummaryEntityId;
                        attrInfo.SummaryExpression = model.SummaryExpression;
                    }
                    break;

                case AttributeTypeIds.MONEY:
                    attrInfo.Precision    = model.MoneyPrecision.Value;
                    attrInfo.MinValue     = model.MoneyMinValue.Value <= float.MinValue ? float.MinValue + 2 : model.MoneyMinValue.Value;
                    attrInfo.MaxValue     = model.MoneyMaxValue.Value >= float.MaxValue ? float.MaxValue - 2 : model.MoneyMaxValue.Value;
                    attrInfo.DefaultValue = model.DefaultValue;
                    if (model.ValueType == 2)
                    {
                        attrInfo.FormulaExpression = model.FormulaExpression;
                    }
                    else if (model.ValueType == 3)
                    {
                        attrInfo.SummaryEntityId   = model.SummaryEntityId;
                        attrInfo.SummaryExpression = model.SummaryExpression;
                    }
                    break;

                case AttributeTypeIds.PICKLIST:
                    attrInfo.DisplayStyle = model.OptionSetType;
                    attrInfo.OptionSet    = _optionSetFinder.FindById(attrInfo.OptionSetId.Value);
                    if (!attrInfo.OptionSet.IsPublic)
                    {
                        if (model.OptionSetName.IsEmpty())
                        {
                            return(JError(T["attribute_options_empty"]));
                        }
                        //选项集
                        List <Schema.Domain.OptionSetDetail> details = new List <Schema.Domain.OptionSetDetail>();
                        int i = 0;
                        foreach (var item in model.OptionSetName)
                        {
                            if (item.IsEmpty())
                            {
                                continue;
                            }

                            Schema.Domain.OptionSetDetail osd = new Schema.Domain.OptionSetDetail();
                            osd.OptionSetDetailId = model.OptionSetDetailId[i];
                            osd.OptionSetId       = attrInfo.OptionSetId.Value;
                            osd.Name         = item;
                            osd.Value        = model.OptionSetValue[i];
                            osd.IsSelected   = model.IsSelectedOption[i];
                            osd.DisplayOrder = i;
                            details.Add(osd);

                            i++;
                        }
                        attrInfo.OptionSet.Items = details;
                    }
                    break;

                case AttributeTypeIds.BIT:
                    //新建选项集
                    List <Schema.Domain.StringMap> pickListItems = new List <Schema.Domain.StringMap>();
                    int j = 0;
                    foreach (var item in model.BitOptionName)
                    {
                        Schema.Domain.StringMap s = new Schema.Domain.StringMap();
                        s.StringMapId   = model.BitDetailId[j];
                        s.Name          = item;
                        s.Value         = j == 0 ? 1 : 0;//第一项为true选项
                        s.DisplayOrder  = j;
                        s.AttributeId   = attrInfo.AttributeId;
                        s.AttributeName = attrInfo.Name;
                        s.EntityName    = attrInfo.EntityName;
                        j++;
                        pickListItems.Add(s);
                    }
                    attrInfo.PickLists = pickListItems;
                    break;

                case AttributeTypeIds.DATETIME:
                    attrInfo.DataFormat = model.DateTimeFormat;
                    break;

                case AttributeTypeIds.LOOKUP:
                    //attrInfo.ReferencedEntityId = model.LookupEntity.Value;
                    break;

                case AttributeTypeIds.PARTYLIST:
                    attrInfo.DataFormat = model.PartyListFormat;
                    break;
                }

                _attributeUpdater.Update(attrInfo);
                return(UpdateSuccess(new { id = attrInfo.AttributeId }));
            }
            return(JModelError(T["saved_error"]));
        }