Пример #1
0
        // GET: ArticlesManage/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Sidebar();
            var temp = db.Articles.FirstOrDefault(s => s.ID == id);

            //防止企业用户串号修改
            if (AccontData.UserType == UserType.Enterprise &&
                temp.EnterpriseID != AccontData.EnterpriseID)
            {
                return(this.ToError("错误", "没有该操作权限", Url.Action("Index")));
            }
            var models = new ArticleCreateEditViewModel
            {
                ID      = temp.ID,
                Title   = temp.Title,
                Content = temp.Content,
            };

            models.Cover.ImageUrl = temp.Images.SplitToArray <string>(',')?[0];
            if (models == null)
            {
                return(HttpNotFound());
            }
            return(View(models));
        }
Пример #2
0
        public ActionResult Edit(ArticleCreateEditViewModel article)
        {
            var temp = db.Articles.FirstOrDefault(s => s.ID == article.ID);

            //防止企业用户串号修改
            if (AccontData.UserType == UserType.Enterprise &&
                temp.EnterpriseID != AccontData.EnterpriseID)
            {
                return(this.ToError("错误", "没有该操作权限", Url.Action("Index")));
            }
            if (ModelState.IsValid)
            {
                if (temp.Type == ArticleType.Html)
                {
                    var t = db.Articles.FirstOrDefault(s => s.ID == article.ID);
                    t.ID      = article.ID;
                    t.Content = article.Content;
                    t.Title   = article.Title;
                    t.Images  = article.Cover.ImageUrl;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(this.ToError("错误", "用户动态不可编辑", Url.Action("Index")));
                }
            }
            Sidebar();
            return(View(article));
        }
Пример #3
0
        // GET: ArticlesManage/Create
        public ActionResult Create()
        {
            Sidebar();
            var model = new ArticleCreateEditViewModel();

            return(View(model));
        }
Пример #4
0
        public ActionResult Create(ArticleCreateEditViewModel article)
        {
            Sidebar();
            var tempuser = db.Users.FirstOrDefault(s => s.Id == AccontData.UserID);

            //防止企业用户串号修改
            if (AccontData.UserType == UserType.Enterprise &&
                tempuser.EnterpriseID != AccontData.EnterpriseID)
            {
                return(this.ToError("错误", "没有该操作权限", Url.Action("Index")));
            }
            if (ModelState.IsValid)
            {
                var model = new Article
                {
                    Images         = article.Cover.ImageUrl,
                    Like           = 0,
                    Share          = 0,
                    State          = ArticleState.Wait,
                    Comment        = 0,
                    Content        = article.Content,
                    CreateDateTime = DateTime.Now,
                    EnterpriseID   = AccontData.EnterpriseID,
                    Title          = article.Title,
                    Type           = ArticleType.Html,
                    UpdateDateTime = DateTime.Now,
                    UserID         = AccontData.UserID,
                    Video          = ""
                };
                db.Articles.Add(model);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(article));
        }