Exemplo n.º 1
0
 public ActionResult Login()
 {
     //Post请求时,验证信息
     if (HttpContext.Request.RequestType == "POST")
     {
         ReturnMsg rmsg = new ReturnMsg();
         string    uid  = Request["uid"];
         string    pwd  = Request["pwd"];
         if (string.IsNullOrWhiteSpace(uid) || string.IsNullOrWhiteSpace(pwd))
         {
             rmsg.Status = 1;
             rmsg.msg    = "您的账户或密码输入为空";
             return(Json(rmsg));
         }
         Models.EFDbContext db = new Models.EFDbContext();
         if (db.UserInfo.Select(a => a.userId == uid && a.userPwd == pwd).Count() == 0)
         {
             rmsg.Status = 1;
             rmsg.msg    = "账户或密码输入错误";
             return(Json(rmsg));
         }
         rmsg.Status = 0;
         rmsg.msg    = "登陆成功";
         return(Json(rmsg));
     }
     //Get请求时,返回页面
     return(View());
 }
        // 新增编辑
        public ActionResult Add(string cate/*内容分类*/, string code/*内容编码*/,
            bool single/*独立页面标识, true: 标识独立*/, int tag/*独立页面标识,枚举类:Models.Article.ArticleTag 的一个实例*/)
        {
            Models.Article article = null;
            ViewData[EDITORFORMACTIONNAME] = "upd";
            if (single)
            {
                article = GetSingleArticle(cate, code, tag);
                return View(article);
            }

            //此处重新编辑
            if (!string.IsNullOrWhiteSpace(code))
            {
                Models.EFDbContext db = new Models.EFDbContext();
                article = db.Articles.Single(t => t.Code == code);
                return View(article);
            }

            ViewData[EDITORFORMACTIONNAME] = "add";
            //此处新增
            if (string.IsNullOrWhiteSpace(cate))
                cate = Models.Article.COMPANYCATEGORY;

            article = new Models.Article() { Category = cate };
            return View(article);
        }
Exemplo n.º 3
0
 public ActionResult Detail(int id)
 {
     Models.EFDbContext db = new Models.EFDbContext();
     Models.Article article = db.Articles.Single(t => t.Id == id);
     return View(article);
 }
        public Models.Article GetSingleArticle(string cate, string code, int tag)
        {
            Models.Article article = null;
            if (!string.IsNullOrWhiteSpace(code))
            {
                Models.EFDbContext db = new Models.EFDbContext();
                article = db.Articles.SingleOrDefault(t => t.Code == code);
            }

            if (article == null)
            {
                ViewData[EDITORFORMACTIONNAME] = "add";
                article = new Models.Article() { Category = cate, Tag = tag };
            }

            return article;
        }
        // 上传文件
        public JsonResult UpFile(HttpPostedFileBase Filedata, string code, int cate)
        {
            string
                uploadpath = "/Upload/imgs/",
                folder = Server.MapPath("~" + uploadpath),
                filename = Filedata.FileName,
                mime = MimeMapping.GetMimeMapping(filename),
                namenoextension = Path.GetFileNameWithoutExtension(filename);

            if (!Directory.Exists(folder))
                Directory.CreateDirectory(folder);

            try
            {
                Filedata.SaveAs(folder + "\\" + filename);
                Models.ArticleFile file = new Models.ArticleFile()
                {
                    Articlecode = code,
                    Category = cate,
                    Name = uploadpath + filename,
                    Title = namenoextension,
                    Mime = mime,
                    Desc = namenoextension
                };

                Models.EFDbContext db = new Models.EFDbContext();
                file = db.ArticleFiles.Add(file);
                int ret = db.SaveChanges();
            }
            catch (Exception e)
            {
                return Json(new { flag = false, message = e.Message });
            }

            return Json(new { flag = true });
        }
        public ActionResult SingleArticles(string cate, int tag)
        {
            Models.EFDbContext db = new Models.EFDbContext();
            Models.Article article = db.Articles.SingleOrDefault(t => t.Category == cate && t.Tag == tag);

            if (article == null)
                article = new Models.Article() { Category = cate, Tag = tag };

            return View(article);
        }