Ejemplo n.º 1
0
 /// <summary>
 /// 管理员添加申请书分类
 /// </summary>
 /// <param name="supportCategoryData"></param>
 /// <returns></returns>
 public void GreateSupportCategorys(SysSupportCategoryAddDTO supportCategoryData)
 {
     using (var db = new AspodesDB())
     {
         if (supportCategoryData.SupportCategoryId == 0)
         {
             //添加项目类别
             ProjectType pj = new ProjectType();
             pj.Name   = supportCategoryData.Name;
             pj.Enable = true;
             db.ProjectTypes.Add(pj);
         }
         else
         {
             //添加支持类别
             if (db.ProjectTypes.Any(c => c.ProjectTypeId == supportCategoryData.SupportCategoryId))
             {
                 //存在项目类别
                 SupportCategory sc = new SupportCategory();
                 sc.Name          = supportCategoryData.Name;
                 sc.ProjectTypeId = supportCategoryData.SupportCategoryId;
                 db.SupportCategorys.Add(sc);
             }
             else
             {
                 //不存在项目类别
                 throw new OtherException("不存在项目类别");
             }
         }
         db.SaveChanges();
     }
 }
Ejemplo n.º 2
0
        public override Support Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            //parse the support meta properties to identify the support type (method, category, sub category)
            var                clonedReader = reader;
            SupportMethod      method       = SupportMethod.Unknown;
            SupportCategory    category     = SupportCategory.Unknown;
            SupportSubCategory subCategory  = SupportSubCategory.None;

            if (clonedReader.TokenType != JsonTokenType.StartObject)
            {
                throw new JsonException($"Invalid json object");
            }

            while (clonedReader.Read())
            {
                if (clonedReader.TokenType != JsonTokenType.PropertyName)
                {
                    continue;
                }
                var propertyName = FirstLetterCapital(clonedReader.GetString());

                clonedReader.Read();
                if (clonedReader.TokenType != JsonTokenType.String || clonedReader.TokenType == JsonTokenType.Null)
                {
                    continue;
                }
                var propertyValue = clonedReader.GetString();
                switch (propertyName)
                {
                case nameof(Support.Method):
                    if (!Enum.TryParse(propertyValue, out method))
                    {
                        throw new JsonException($"Invalid support method");
                    }
                    break;

                case nameof(Support.Category):
                    if (!Enum.TryParse(propertyValue, out category))
                    {
                        throw new JsonException($"Invalid support category");
                    }
                    break;

                case nameof(Support.SubCategory):
                    if (!Enum.TryParse(propertyValue, out subCategory))
                    {
                        throw new JsonException($"Invalid support sub category");
                    }
                    break;
                }
            }

            if (method == SupportMethod.Unknown || category == SupportCategory.Unknown)
            {
                throw new JsonException($"Could not determine the support method or category");
            }

            //Dserialize to the correct type
            return(category switch
            {
                SupportCategory.Clothing => JsonSerializer.Deserialize <ClothingSupport>(ref reader, options),
                SupportCategory.Incidentals => JsonSerializer.Deserialize <IncidentalsSupport>(ref reader, options),
                SupportCategory.Food when subCategory == SupportSubCategory.Food_Groceries => JsonSerializer.Deserialize <FoodGroceriesSupport>(ref reader, options),
                SupportCategory.Food when subCategory == SupportSubCategory.Food_Restaurant => JsonSerializer.Deserialize <FoodRestaurantSupport>(ref reader, options),
                SupportCategory.Lodging when subCategory == SupportSubCategory.Lodging_Hotel => JsonSerializer.Deserialize <LodgingHotelSupport>(ref reader, options),
                SupportCategory.Lodging when subCategory == SupportSubCategory.Lodging_Billeting => JsonSerializer.Deserialize <LodgingBilletingSupport>(ref reader, options),
                SupportCategory.Lodging when subCategory == SupportSubCategory.Lodging_Group => JsonSerializer.Deserialize <LodgingGroupSupport>(ref reader, options),
                SupportCategory.Transportation when subCategory == SupportSubCategory.Transportation_Taxi => JsonSerializer.Deserialize <TransportationTaxiSupport>(ref reader, options),
                SupportCategory.Transportation when subCategory == SupportSubCategory.Transportation_Other => JsonSerializer.Deserialize <TransportationOtherSupport>(ref reader, options),
                _ => throw new NotSupportedException($"Support with method {method}, category {category}, sub category {subCategory}")
            });
Ejemplo n.º 3
0
        public ApplicationStepOneLeftDTO GetStepOneLeft(string id)
        {
            ApplicationStepOneLeftDTO stepOneLeft = null;

            using (var ctx = new AspodesDB())
            {
                Application application = ctx.Applications.FirstOrDefault(a => a.ApplicationId == id);
                if (null != application)
                {
                    stepOneLeft = Mapper.Map <ApplicationStepOneLeftDTO>(application);
                }
                else
                {
                    stepOneLeft = new ApplicationStepOneLeftDTO();
                    stepOneLeft.ApplicationId = id;
                }

                stepOneLeft.ProjectTypes = ctx.ProjectTypes.Select(Mapper.Map <GetProjectTypeDTO>).ToList();
                if (!stepOneLeft.ProjectTypeId.HasValue)
                {
                    ProjectType type = ctx.ProjectTypes.FirstOrDefault();
                    stepOneLeft.ProjectTypeName = type.Name;
                    stepOneLeft.ProjectTypeId   = type.ProjectTypeId;
                }

                stepOneLeft.SupportCategorys = ctx.SupportCategorys
                                               .Where(sc => sc.ProjectTypeId == stepOneLeft.ProjectTypeId)
                                               .Select(Mapper.Map <GetSupportCategoryDTO>)
                                               .ToList();
                if (!stepOneLeft.SupportCategoryId.HasValue)
                {
                    SupportCategory supportCategory = ctx.SupportCategorys.FirstOrDefault();
                    stepOneLeft.SupportCategoryId   = supportCategory.SupportCategoryId;
                    stepOneLeft.SupportCategoryName = supportCategory.Name;
                }

                stepOneLeft.Fields = ctx.Fields.ToList();
                List <ApplicationField> applicationFields = ctx.ApplicationFields.Where(af => af.ApplicationId == id).ToList();

                if (applicationFields.Count < SystemConfig.ApplicationFieldAmount)
                {
                    SubField subField = ctx.SubFields.FirstOrDefault(sf => sf.SubFieldName != null);
                    while (applicationFields.Count < SystemConfig.ApplicationFieldAmount)
                    {
                        applicationFields.Add(new ApplicationField {
                            SubFieldId = subField.SubFieldName
                        });
                    }
                }

                foreach (var applicationField in applicationFields)
                {
                    SubField subField           = ctx.SubFields.FirstOrDefault(sf => sf.SubFieldName == applicationField.SubFieldId);
                    var      applicationFieldVO = Mapper.Map <ApplicationFieldVO>(applicationField);
                    applicationFieldVO.FieldId   = subField.ParentName;
                    applicationFieldVO.SubFields = ctx.SubFields
                                                   .Where(sf => sf.ParentName == subField.ParentName)
                                                   .Select(Mapper.Map <GetSubFieldDTO>)
                                                   .ToList();
                    stepOneLeft.ApplicationFields.Add(applicationFieldVO);
                }
            }
            return(stepOneLeft);
        }