Esempio n. 1
0
        public ActionResult Delete(int id)
        {
            var post = MiscService.GetById(id);

            if (post is null)
            {
                return(ResultData(null, false, "杂项页已经被删除!"));
            }

            var srcs = post.Content.MatchImgSrcs().Where(s => s.StartsWith("/"));

            foreach (var path in srcs)
            {
                try
                {
                    System.IO.File.Delete(Path.Combine(HostEnvironment.WebRootPath + path));
                }
                catch (IOException)
                {
                }
            }

            bool b = MiscService.DeleteByIdSaved(id);

            return(ResultData(null, b, b ? "删除成功" : "删除失败"));
        }
Esempio n. 2
0
        public ActionResult Index(int id)
        {
            Misc misc = MiscService.GetById(id);

            if (misc is null)
            {
                return(RedirectToAction("Index", "Error"));
            }
            return(View(misc));
        }
Esempio n. 3
0
        public ActionResult Edit(Misc misc)
        {
            var entity = MiscService.GetById(misc.Id);

            entity.ModifyDate = DateTime.Now;
            entity.Title      = misc.Title;
            entity.Content    = CommonHelper.ReplaceImgSrc(Regex.Replace(misc.Content, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>")).Replace("/thumb150/", "/large/");
            bool b = MiscService.UpdateEntitySaved(entity);

            return(ResultData(null, b, b ? "修改成功" : "修改失败"));
        }
Esempio n. 4
0
        public ActionResult Get(int id)
        {
            var misc = MiscService.GetById(id);

            if (misc != null)
            {
                misc.ModifyDate = misc.ModifyDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone));
                misc.PostDate   = misc.PostDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone));
            }
            return(ResultData(misc.MapTo <MiscDto>()));
        }
Esempio n. 5
0
        public async Task <ActionResult> Edit(Misc misc)
        {
            var entity = MiscService.GetById(misc.Id);

            entity.ModifyDate = DateTime.Now;
            entity.Title      = misc.Title;
            entity.Content    = await ImagebedClient.ReplaceImgSrc(misc.Content.ClearImgAttributes());

            bool b = MiscService.SaveChanges() > 0;

            return(ResultData(null, b, b ? "修改成功" : "修改失败"));
        }
Esempio n. 6
0
        public ActionResult Get(int id)
        {
            var notice = MiscService.GetById(id);

            return(ResultData(notice.MapTo <MiscOutputDto>()));
        }
Esempio n. 7
0
 public ActionResult _Edit(int id)
 {
     return(PartialView(_miscService.GetById(id)));
 }