Esempio n. 1
0
        public ActionResult AddArticle(FormCollection form)
        {
            User u = user.getUser((Session["User"] as LoginForm).Id);
            if (u.Role_Id <= 2)
            {
                Article art = new Article();
                art.Title = form["Title"];
                art.Content = form["Content"];
                art.CreateTime = DateTime.Now;
                art.UserId = (Session["User"] as LoginForm).Id;
                HttpFileCollectionBase file = Request.Files;
                if (file != null)
                {
                    string filename = file["file"].FileName;
                    string path = AppDomain.CurrentDomain.BaseDirectory + "/Files/Article/";
                    Document d = new Document();
                    d.IsArticle = true;
                    d.IsShare = true;
                    d.Name = filename;
                    d.UserId = u.Id;
                    d.UserName = u.UserName;
                    d.CreateTime = DateTime.Now;
                    d.Size = file["file"].ContentLength;
                    if (!document.AddDocument(d))
                    {
                        ViewData["Error"] = "出错了,请与管理员联系";
                        return View();
                    }
                    try
                    {
                        file["file"].SaveAs(Path.Combine(path, filename));
                    }
                    catch
                    {
                        ViewData["Error"] = "文件保存失败";
                        return View();
                    }
                    art.documentId = d.Id;
                }
                if (!article.addArticle(art))
                {
                    ViewData["Error"] = "出错了,请与管理员联系";
                    return View();
                }
                return RedirectToAction("Index", "Index");
            }
            else
            {

                return RedirectToAction("ForbidPage", "Error");
            }
        }
Esempio n. 2
0
 public Boolean deleteArticle(Article article)
 {
     try
       {
           db.Set<Article>().Remove(article);
           db.SaveChanges();
       }
       catch
       {
           return false;
       }
       return true;
 }
Esempio n. 3
0
 public Boolean addArticle(Article article)
 {
     try
       {
           db.Set<Article>().Add(article);
           db.SaveChanges();
       }
       catch
       {
           return false;
       }
       return true;
 }