Example #1
0
        public async Task <ActionResult> Edit(CategoryModel model)
        {
            var entity = await easonRepository.GetAsync(model.id);

            if (entity != null && entity.title != model.title)
            {
                entity.title = model.title;
                await easonRepository.UpdateAsync(entity);

                await easonRepository.UnitOfWork.CommitAsync();
            }

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit(PublishArticle model)
        {
            if (model == null)
            {
                ModelState.AddModelError("", "数据不允许为空!!");
            }

            if (string.IsNullOrEmpty(model.title))
            {
                ModelState.AddModelError("", "标题不允许为空!!");
            }



            var art = await repository.GetAsync(model.id);

            var cate = new EasonRepository <ArticleCategory, long>();
            var ct   = await cate.GetAsync(model.categoryId);

            if (art == null)
            {
                ModelState.AddModelError("", "该文章可能已经被删除!");
            }
            if (ModelState.IsValid)
            {
                art.title        = model.title;
                art.contents     = model.contents;
                art.creationTime = DateTime.Now;
                art.status       = model.status;
                art.categoryId   = model.categoryId;
                // art.typeId = model.typeId;
                art.creatorName  = User.Identity.Name;
                art.imageUrl     = model.imageUrl;
                art.videoUrl     = model.videoUrl;
                art.mTitle       = model.mTitle;
                art.desc         = model.desc;
                art.outLink      = model.outLink;
                art.categoryName = ct.title;
                art.creatorId    = long.Parse((User.Identity as ClaimsIdentity).Claims.FirstOrDefault(m => m.Type == ClaimTypes.Sid).Value);
                await repository.UpdateAsync(art);

                await repository.UnitOfWork.CommitAsync();

                return(Jsonp(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            return(View(model));
        }
        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));
            }
        }
        // GET: Acitity
        public async System.Threading.Tasks.Task <ActionResult> Index(string hdname)
        {
            var result = new ResultModel();

            if (string.IsNullOrEmpty(hdname))
            {
                result.Code    = 1002;
                result.Message = " hdname ";
                return(Jsonp(result, JsonRequestBehavior.AllowGet));
            }

            var entity = repository.FirstOrDefault(i => i.hdname == hdname);

            if (entity != null)
            {
                entity.hdnum += 1;
                await repository.UpdateAsync(entity);

                await repository.UnitOfWork.CommitAsync();
            }
            else
            {
                entity              = new Forward();
                entity.hdname       = hdname;
                entity.hdnum        = 1;
                entity.creationTime = DateTime.Now;
                entity.creatorId    = 0;
                entity.creatorName  = "分享用户";
                entity.status       = 0;
                repository.Insert(entity);
                await repository.UnitOfWork.CommitAsync();
            }
            result.Code    = 0;
            result.Message = "success";
            return(Jsonp(result, JsonRequestBehavior.AllowGet));
        }