Esempio n. 1
0
        public IActionResult EditOptionSet(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. 2
0
 public IActionResult CreateOptionSet(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"]));
         }
         Schema.Domain.OptionSet os = new Schema.Domain.OptionSet();
         os.OptionSetId = Guid.NewGuid();
         os.Name        = model.Name;
         os.IsPublic    = true;
         os.SolutionId  = model.SolutionId;
         os.CreatedBy   = CurrentUser.SystemUserId;
         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 = Guid.NewGuid();
             osd.OptionSetId       = os.OptionSetId;
             osd.Name         = item;
             osd.Value        = model.OptionSetValue[i];
             osd.IsSelected   = model.IsSelectedOption[i];
             osd.DisplayOrder = i;
             details.Add(osd);
             i++;
         }
         os.Items = details;
         _optionSetCreater.Create(os);
         return(CreateSuccess(new { id = os.OptionSetId }));
     }
     return(CreateFailure(GetModelErrors()));
 }
Esempio n. 3
0
        public IActionResult EditAttribute(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.LogEnabled;
                attrInfo.IsRequired           = model.IsRequired;
                attrInfo.AuthorizationEnabled = model.AuthorizationEnabled;
                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.DisplayStyle = model.LookupType;
                    //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"]));
        }
Esempio n. 4
0
        public IActionResult CreateAttribute(CreateAttributeModel model)
        {
            if (ModelState.IsValid)
            {
                var entity = _entityFinder.FindById(model.EntityId);
                if (entity == null)
                {
                    return(NotFound());
                }
                var attr = _attributeFinder.Find(model.EntityId, model.Name);
                if (attr != null)
                {
                    return(JError(T["attribute_name_exists"]));
                }
                var attrInfo = new Schema.Domain.Attribute();
                //model.CopyTo(entity);
                attrInfo.EntityId             = entity.EntityId;
                attrInfo.EntityName           = entity.Name;
                attrInfo.Name                 = model.Name.Trim();
                attrInfo.LocalizedName        = model.LocalizedName;
                attrInfo.AttributeId          = Guid.NewGuid();
                attrInfo.IsNullable           = model.IsNullable;
                attrInfo.IsRequired           = model.IsRequired;
                attrInfo.LogEnabled           = model.LogEnabled;
                attrInfo.IsCustomizable       = true;
                attrInfo.IsCustomField        = true;
                attrInfo.AuthorizationEnabled = model.AuthorizationEnabled;
                attrInfo.CreatedBy            = CurrentUser.SystemUserId;
                attrInfo.Description          = model.Description;
                attrInfo.ValueType            = model.ValueType;
                switch (model.AttributeType)
                {
                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;
                    if (model.IsCommonOptionSet)
                    {
                        attrInfo.OptionSetId = model.CommonOptionSet.Value;
                    }
                    else
                    {
                        if (model.OptionSetName.IsEmpty())
                        {
                            return(JError(T["attribute_options_empty"]));
                        }
                        //新建选项集
                        Schema.Domain.OptionSet os = new Schema.Domain.OptionSet();
                        os.OptionSetId = Guid.NewGuid();
                        os.Name        = model.Name;
                        os.IsPublic    = false;
                        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 = Guid.NewGuid();
                            osd.OptionSetId       = os.OptionSetId;
                            osd.Name         = item;
                            osd.Value        = model.OptionSetValue[i];
                            osd.IsSelected   = model.IsSelectedOption[i];
                            osd.DisplayOrder = i;
                            details.Add(osd);
                            i++;
                        }
                        attrInfo.OptionSetId = os.OptionSetId;
                        os.Items             = details;
                        attrInfo.OptionSet   = os;
                    }
                    break;

                case AttributeTypeIds.BIT:
                    if (model.BitOptionName.IsEmpty())
                    {
                        return(JError(T["attribute_options_empty"]));
                    }
                    //新建选项集
                    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   = Guid.NewGuid();
                        s.Name          = item;
                        s.Value         = j == 0 ? 1 : 0;//第一项为true选项
                        s.DisplayOrder  = j;
                        s.AttributeId   = attrInfo.AttributeId;
                        s.EntityName    = attrInfo.EntityName;
                        s.AttributeName = attrInfo.Name;
                        j++;
                        pickListItems.Add(s);
                    }
                    attrInfo.PickLists = pickListItems;
                    break;

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

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

                case AttributeTypeIds.PARTYLIST:
                    attrInfo.DataFormat = model.PartyListFormat;
                    break;
                }
                attrInfo.AttributeTypeName = model.AttributeType;
                _attributeCreater.Create(attrInfo);
                return(CreateSuccess(new { id = attrInfo.AttributeId }));
            }
            return(JModelError(T["created_error"]));
        }