Exemple #1
0
        public virtual ActionResult Add()
        {
            var id         = Id;
            var targetId   = this.TargetId;
            var categoryId = this.CategoryId;

            if (id.HasValue)
            {
                var r = IComCountService.Add(id.Value, this.Count, this.Table);
                return(this.ResponseJson(r));
            }
            else if (targetId.HasValue && IValidatorTool.IsNotEmpty(categoryId))
            {
                var r = IComCountService.Add(targetId.Value, categoryId, this.Count, this.Table);
                return(this.ResponseJson(r));
            }
            else
            {
                return(ResponseJson(new GenericExecResult <object>()
                {
                    Success = false,
                    Message = "请输入相应的参数id或targetId与categoryId"
                }));
            }
        }
Exemple #2
0
 public virtual ActionResult Find()
 {
     if (this.Id.HasValue)
     {
         var r = IComCountService.FindById(this.Id.Value);
         return(this.ResponseJson(r));
     }
     else if (TargetId.HasValue && IValidatorTool.IsNotEmpty(CategoryId))
     {
         var r = IComCountService.FindFirstOrDefaultByTargetIdAndCategoryId(this.TargetId.Value, this.CategoryId, this.Table);
         return(this.ResponseJson(r));
     }
     else if (this.TargetId.HasValue)
     {
         var r = IComCountService.FindByTargetId(this.TargetId.Value, this.Table);
         return(this.ResponseJson(r));
     }
     else
     {
         return(ResponseJson(new GenericExecResult <object>()
         {
             Success = false,
             Message = "请输入相应的参数id或targetId与categoryId"
         }));
     }
 }
Exemple #3
0
        public Com_Count FirstOrDefaultByTargetIdAndCategoryId(Guid targetId, string categoryId)
        {
            var list = this.FindByProperties(Where.Create().Eq("TargetId", targetId).Eq("CategoryId", categoryId));

            if (IValidatorTool.IsEmpty(list))
            {
                return(null);
            }
            return(list[0]);
        }
Exemple #4
0
        public static T RequestParam <T>(string parameterName, T defaultValue = default(T))
        {
            IValidatorTool validator       = ToolFactory.CreateIValidatorTool();
            var            srcRequestValue = Request[parameterName];

            if (validator.IsEmpty(srcRequestValue))
            {
                return(default(T));
            }
            T value = ToolFactory.CreateIProgramTool().ChanageType <T>(srcRequestValue);

            if (value == null && defaultValue != null)
            {
                return(defaultValue);
            }
            return(value);
        }
Exemple #5
0
        /// <summary>
        /// 从匹配的目标路由集合中查找匹配的目标路由
        /// </summary>
        /// <param name="formRouteData">源路由数据</param>
        /// <returns>配置的目标路由数据</returns>
        public AbstractMethodRouteData FindRouteData(MethodFormRouteData formRouteData)
        {
            var baseRouteData = base.FindRouteData(formRouteData);

            if (IValidatorTool.IsEmpty(baseRouteData))
            {
                throw new Exception(string.Format("没有查找到{0},相关的映射方法", formRouteData.Form));
            }
            if (baseRouteData.Count == 1)
            {
                return((AbstractMethodRouteData)baseRouteData[0]);
            }

            var methodFormRouteData = (MethodFormRouteData)formRouteData;
            List <AbstractMethodRouteData> methodRouteDatas = new List <AbstractMethodRouteData>(baseRouteData.Count);

            foreach (var item in baseRouteData)
            {
                methodRouteDatas.Add((AbstractMethodRouteData)item);
            }
            IList <AbstractMethodRouteData> routeDatas = this.FindMaxMatchRouteDatas(methodFormRouteData, methodRouteDatas);

            if (IValidatorTool.IsEmpty(routeDatas))
            {
                throw new Exception(string.Format("没有查找到{0},相关的映射方法", methodFormRouteData.Form));
            }

            if (routeDatas.Count > 1)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("{0},查找到多个映射方法", methodFormRouteData.Form);
                foreach (var item in routeDatas)
                {
                    var reflectorRouteData = (AbstractMethodRouteData)item;
                    sb.AppendLine(reflectorRouteData.ServiceType.FullName + "." + reflectorRouteData.MethodInfo.Name);
                }
                throw new Exception(sb.ToString());
            }
            return(routeDatas[0]);
        }