Ejemplo n.º 1
0
        public IHttpActionResult GetNewsReads(int NewsInfoId)
        {
            var model = _newsInfoService.GetById(NewsInfoId);

            if (model != null)
            {
                model.Reads = +1;
                _newsInfoService.Update(model);
            }
            return(Json(new { Success = true, Msg = "OK", Data = model.Reads }));
        }
Ejemplo n.º 2
0
        public JsonResult Edit(NewsInfo model)
        {
            try
            {
                var entity = new NewsInfo();
                if (model.NewsInfoId > 0)
                {
                    entity = _newsInfoService.GetById(model.NewsInfoId);
                    //修改
                    entity.UTime          = DateTime.Now;
                    entity.ImageInfoId    = model.ImageInfoId;
                    entity.NewsCategoryId = model.NewsCategoryId;
                    entity.Title          = model.Title;
                    entity.Author         = model.Author;
                    entity.Content        = model.Content;
                    entity.Sort           = model.Sort;
                    entity.isHot          = model.isHot;
                    entity.isTop          = model.isTop;
                    _newsInfoService.Update(entity);
                }
                else
                {
                    if (_newsInfoService.IsExistName(model.Title))
                    {
                        return(Json(new { Status = Successed.Repeat }, JsonRequestBehavior.AllowGet));
                    }
                    //添加
                    entity.Title          = model.Title;
                    entity.ImageInfoId    = model.ImageInfoId;
                    entity.NewsCategoryId = model.NewsCategoryId;
                    entity.Title          = model.Title;
                    entity.Author         = model.Author;
                    entity.Content        = model.Content;
                    entity.Sort           = model.Sort;
                    entity.isHot          = model.isHot;
                    entity.isTop          = model.isTop;
                    entity.CTime          = DateTime.Now;
                    entity.UTime          = DateTime.Now;

                    _newsInfoService.Insert(entity);
                }
                return(Json(new { Status = Successed.Ok }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Status = Successed.Error }, JsonRequestBehavior.AllowGet));
            }
        }