Exemplo n.º 1
0
 protected ActionResult RestfulResult(ExecuteResult data)
 {
     return new RestfulResult
     {
         Data = data
     };
 }
Exemplo n.º 2
0
        public RestfulResult Del(FormCollection formCollection, [FetchProduct(KeyName = "productid")]ProductEntity model)
        {
            var name = model.Name;
            _productRepository.Delete(model);

            var result = new ExecuteResult { StatusCode = StatusCode.Success, Message = name + "删除成功" };

            return new RestfulResult
                {
                    Data = result
                };
        }
        /// <summary>
        /// 记录asp.net未捕获的异常
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnError(object sender, EventArgs e)
        {
            var context = HttpContext.Current;
            if (context == null) return;

            var exception = context.Server.GetLastError();
            if (exception == null) return;


            //var httpException = exception as HttpException;

            //if (httpException != null)
            //{
            //    httpException.GetHttpCode();
            //}

            //包括记录异常的内部包含异常
            while (exception != null)
            {
                //_log.Error("Global:");
                _log.Error(exception);
                exception = exception.InnerException;
            }

            context.Server.ClearError();
            context.Response.TrySkipIisCustomErrors = true;

            //输出错误信息

            var format = context.Request[Define.Format];

            if (String.IsNullOrEmpty(format))
            {
                format = String.Empty; // 如果为空,将会使用默认值
            }
            string response;
            var result = new ExecuteResult
                             {
                                 Message = "服务器正在维护请稍后重试!",
                                 StatusCode = StatusCode.InternalServerError
                             };

            switch (format.ToLower())
            {
                case Define.Json:
                    response = Utils.DataContractToJson(result);
                    context.Response.ContentType = "application/json; charset=utf-8";
                    break;
                case Define.Xml:
                    response = result.ToXml();
                    context.Response.ContentType = "text/xml; charset=utf-8";
                    break;
                default:
                    response = result.Message;
                    context.Response.ContentType = "text/html; charset=utf-8";
                    break;
            }

            context.Response.ClearHeaders();
            context.Response.Clear();
            context.Response.StatusCode = 200;

            context.Response.Write(response);
        }
Exemplo n.º 4
0
        public ActionResult Create(FormCollection formCollection, TagCreateViewModel vo)
        {
            var jsonResult = new JsonResult { ContentEncoding = Encoding.UTF8 };

            var result = new ExecuteResult<int>();

            if (ModelState.IsValid)
            {
                var tmpEntity = Mapper.Map<TagCreateViewModel, TagEntity>(vo);
                tmpEntity.Status = (int)DataStatus.Normal;
                tmpEntity.UpdatedDate = DateTime.Now;
                tmpEntity.UpdatedUser = CurrentUser.CustomerId;
                tmpEntity.CreatedDate = DateTime.Now;
                tmpEntity.CreatedUser = CurrentUser.CustomerId;
                tmpEntity.User_Id = CurrentUser.CustomerId;


                var userEntity = ServiceInvoke(unitOfWork => unitOfWork.TagRepository.Insert(tmpEntity));

                result.Data = userEntity.Id;

            }
            else
            {
                result.StatusCode = StatusCode.ClientError;
            }

            jsonResult.Data = result;

            return jsonResult;
        }
Exemplo n.º 5
0
        public ActionResult Delete(FormCollection formCollection, [FetchTag(KeyName = "tagid")]TagEntity model)
        {
            model.UpdatedDate = DateTime.Now;
            model.UpdatedUser = CurrentUser.CustomerId;
            model.Status = (int)DataStatus.None;

            var jsonResult = new JsonResult { ContentEncoding = Encoding.UTF8 };

            var result = new ExecuteResult<int>();


            ServiceInvoke<INGnono_FMNoteContextEFUnitOfWork>(v => v.TagRepository.Update(model));

            jsonResult.Data = result;

            return jsonResult;
        }
Exemplo n.º 6
0
        public ActionResult Edit(FormCollection formCollection, [FetchBill(KeyName = "billid")]BillEntity model, BillViewModel vo)
        {
            var jsonResult = new JsonResult { ContentEncoding = Encoding.UTF8 };

            var result = new ExecuteResult<int>();

            if (ModelState.IsValid)
            {
                var tmp = Mapper.Map<BillViewModel, BillEntity>(vo);
                tmp.UpdatedDate = DateTime.Now;
                tmp.UpdatedUser = CurrentUser.CustomerId;
                tmp.Status = model.Status;
                tmp.CreatedDate = model.CreatedDate;
                tmp.CreatedUser = model.CreatedUser;
                tmp.Status = model.Status;
                tmp.IsDeleted = model.IsDeleted;

                Mapper.Map(tmp, model);

                Update(model);
            }
            else
            {
                result.StatusCode = StatusCode.ClientError;
                result.Message = "参数验证错误";
            }

            jsonResult.Data = result;

            return jsonResult;
        }
Exemplo n.º 7
0
        public ActionResult Delete(FormCollection formCollection, [FetchBill(KeyName = "billid")]BillEntity model)
        {
            Del(model, CurrentUser.CustomerId);

            var jsonResult = new JsonResult { ContentEncoding = Encoding.UTF8 };

            var result = new ExecuteResult<int>();

            jsonResult.Data = result;

            return jsonResult;
        }
Exemplo n.º 8
0
        public ActionResult Create(FormCollection formCollection, BillViewModel vo)
        {
            var jsonResult = new JsonResult { ContentEncoding = Encoding.UTF8 };

            var result = new ExecuteResult<int>();

            if (ModelState.IsValid)
            {
                var billEntity = Mapper.Map<BillViewModel, BillEntity>(vo);
                billEntity.CreatedDate = DateTime.Now;
                billEntity.CreatedUser = CurrentUser.CustomerId;
                billEntity.UpdatedDate = DateTime.Now;
                billEntity.UpdatedUser = CurrentUser.CustomerId;
                billEntity.Status = (int)DataStatus.Normal;

                var entity = Insert(billEntity);

                result.Data = entity.Id;
            }
            else
            {
                result.StatusCode = StatusCode.ClientError;
            }

            jsonResult.Data = result;

            return jsonResult;
        }