Esempio n. 1
0
        public override System.Threading.Tasks.Task<HttpResponseMessage> ExecuteAsync(System.Web.Http.Controllers.HttpControllerContext controllerContext, System.Threading.CancellationToken cancellationToken)
        {
            string modeltype = "", modelinbody = "";
            try
            {
                IEnumerable<string> mts = controllerContext.Request.Headers.GetValues("ModelType");
                IEnumerable<string> mlbs = controllerContext.Request.Headers.GetValues("ModelInBody");
                IEnumerable<string> mig = controllerContext.Request.Headers.GetValues("HeadMethod");
                IEnumerable<string> act = controllerContext.Request.Headers.GetValues("AccessToken");
                if (mts.Count() > 0)
                    modeltype = mts.First();
                if (mlbs.Count() > 0)
                    modelinbody = mlbs.First();
                if (mig.Count() > 0)
                    headmethod = mig.First();
                if (act.Count() > 0)
                    this.AccessToken = act.First();
                if (string.IsNullOrEmpty(this.AccessToken))
                {
                    if (!modeltype.Equals("BarcodeModel.MODEL.User.LoginModel"))
                    {
                        throw new Exception("无法访问,未登录系统");
                    }
                }
                else
                    this.GetLoginUser(this.AccessToken, modeltype);
                if (!string.IsNullOrEmpty(modeltype))
                {
                    Type t = BaseSearchModel.GetType(modeltype);
                    if (modelinbody == "true" && headmethod == "getids")//获取
                    {
                        ids = (string[])controllerContext.Request.Content.ReadAsAsync(typeof(string[])).Result;
                    }
                    else if (modelinbody == "true" && headmethod != "delete")//获取
                    {
                        enableSearch = true;
                        searchModel = (BaseSearchModel)controllerContext.Request.Content.ReadAsAsync(t).Result;
                    }
                    else if (modelinbody == "true" && headmethod == "delete")//批量删除
                    {
                        ids = (string[])controllerContext.Request.Content.ReadAsAsync(typeof(string[])).Result;
                    }
                    if (searchModel == null)
                    {
                        Assembly ass = Assembly.GetAssembly(t);
                        searchModel = (BaseSearchModel)ass.CreateInstance(t.FullName);
                    }

                    searchModel.LoginUserID = this.loginUserID;
                    searchModel.LoginUserName = this.loginUserName;

                }
            }
            catch (Exception ex)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent("无效请求"),
                    ReasonPhrase = "无效请求"
                };
                throw new HttpResponseException(resp);
            }
            return base.ExecuteAsync(controllerContext, cancellationToken);
        }
Esempio n. 2
0
 public virtual int Update(BaseSearchModel model)
 {
     return this.GetADO().Update(model);
 }