예제 #1
0
        public async Task <ActionResult> Edit(Misc misc)
        {
            var entity = await MiscService.GetByIdAsync(misc.Id) ?? throw new NotFoundException("杂项页未找到");

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

            bool b = await MiscService.SaveChangesAsync() > 0;

            return(ResultData(null, b, b ? "修改成功" : "修改失败"));
        }
예제 #2
0
        public async Task <ActionResult> Get(int id)
        {
            var misc = await MiscService.GetByIdAsync(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.Mapper <MiscDto>()));
        }
예제 #3
0
        public async Task <ActionResult> Delete(int id)
        {
            var post = await MiscService.GetByIdAsync(id) ?? throw new NotFoundException("杂项页已被删除!");

            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 = await MiscService.DeleteByIdSavedAsync(id) > 0;

            return(ResultData(null, b, b ? "删除成功" : "删除失败"));
        }