コード例 #1
0
        public async System.Threading.Tasks.Task <ActionResult> ItemAsync(long?id)
        {
            var result = new ResultModel();

            if (id == null || id < 0)
            {
                result.Code    = 1002;
                result.Message = " id ";
                return(Jsonp(result, JsonRequestBehavior.AllowGet));
            }
            try
            {
                var item = await repository.SingleAsync(m => m.id == id && m.status == 0);

                if (item != null)
                {
                    item.readNum += 1;
                    await repository.UpdateAsync(item);

                    await repository.UnitOfWork.CommitAsync();

                    var data = Mapper.Map <Article, ArticleItemModel>(item);
                    result.Code    = 0;
                    result.Message = string.Empty;
                    result.Data    = data;
                    return(Jsonp(result, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    result.Code    = 0;
                    result.Message = "not found";
                    return(Jsonp(result, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                result.Code    = 1001;
                result.Message = ex.Message;
                return(Jsonp(result, JsonRequestBehavior.AllowGet));
            }
        }