Exemplo n.º 1
0
        public async Task <IActionResult> Edit(
            int nid, NewsEditModel model,
            [FromServices] IMarkdownService markdownService)
        {
            if (model.NewsId != nid)
            {
                return(BadRequest());
            }

            var news = await DbContext.News
                       .Where(n => n.NewsId == nid)
                       .FirstOrDefaultAsync();

            if (news is null)
            {
                return(NotFound());
            }

            markdownService.Render(model.MarkdownSource, out var html, out var tree);
            news.Source     = Encoding.UTF8.GetBytes(model.MarkdownSource);
            news.Title      = model.Title;
            news.Active     = model.Active;
            news.Content    = Encoding.UTF8.GetBytes(html);
            news.Tree       = Encoding.UTF8.GetBytes(tree);
            news.LastUpdate = DateTimeOffset.Now;

            await DbContext.SaveChangesAsync();

            StatusMessage = "News updated successfully.";
            return(RedirectToAction(nameof(Edit), new { nid }));
        }
Exemplo n.º 2
0
 protected override void OnNewsEdited(NewsBase news, NewsEditModel model)
 {
     if (model is NewsExtendedEditModel extendedModel)
     {
         _activityTagsHelper.ReplaceTags(news.Id, extendedModel.TagIdsData);
     }
 }
Exemplo n.º 3
0
        public IActionResult UpdateNews(Guid id, [Bind("Title,Description, CreatedBy")] NewsEditModel newsEditModel)
        {
            var newsEdited = _service.GetNewsById(id);

            if (newsEdited == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View(newsEditModel));
            }

            newsEdited.Title       = newsEditModel.Title;
            newsEdited.Description = newsEditModel.Description;

            try
            {
                _service.Update(newsEdited);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NewsExists(_service.GetNewsById(id).Id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(RedirectToAction(nameof(Index)));
        }
 public ActionResult Edit([Bind(Include = "Id,Title,Text,File")] NewsEditModel model)
 {
     if (ModelState.IsValid)
     {
         News news = db.news.Single(s => s.Id == model.Id);
         if (news == null)
         {
             return(HttpNotFound());
         }
         news.Title = model.Title;
         news.Text  = model.Text;
         if (model.File != null && model.File.ContentLength > 0)
         {
             var fileExtension = Path.GetExtension(model.File.FileName);
             var fileName      = Path.GetFileNameWithoutExtension(model.File.FileName) + "-" +
                                 DateTime.Now.ToString("yyyyMMdd_HHmmssfff") + fileExtension;
             var path = Path.Combine(Server.MapPath("~/Img/news"), fileName);
             model.File.SaveAs(path);
             news.PicturePath = "/Img/news/" + fileName;
         }
         news.Modified = DateTime.Now;
         db.SaveChanges();
         TempData["AlertMessage"] = "changes has ended succesfully";
         return(RedirectToAction("List"));
     }
     TempData["AlertMessage"] = "Something gone wrong. Try again please!";
     return(RedirectToAction("List"));
 }
Exemplo n.º 5
0
        public async Task <IHttpActionResult> Edit(NewsEditModel editModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            //if (!_permissionsService.Check(new PermissionSettingIdentity(PermissionActionEnum.Edit,
            //    PermissionResourceTypeEnum.News)))
            if (!await _newsService.CanEditAsync(editModel.Id))
            {
                return(Ok((await _activityLinkService.GetLinksAsync(editModel.Id)).Details));
            }

            var cachedActivityMedias = _newsService.Get(editModel.Id).MediaIds;

            var activity = MapToNews(editModel);
            await _newsService.SaveAsync(activity);

            DeleteMedia(cachedActivityMedias.Except(activity.MediaIds));

            await OnNewsEditedAsync(activity, editModel);

            var newsViewModel = await GetViewModelAsync(_newsService.Get(editModel.Id));

            ReloadFeed();
            return(Ok(newsViewModel.Links.Details));
        }
Exemplo n.º 6
0
        protected override void OnNewsEdited(NewsBase news, NewsEditModel model)
        {
            if (model is NewsExtendedEditModel extendedModel)
            {
                _activityTagsHelper.ReplaceTags(news.Id, extendedModel.TagIdsData);
            }

            ResolveMentions(model.Description, news);
        }
Exemplo n.º 7
0
        public int Save(NewsEditModel model)
        {
            var news = new News
            {
                Id      = model.Id,
                Title   = model.Title,
                Content = model.Content,
                Date    = model.Date
            };

            return(_newsRepository.InsertOrUpdate(news));
        }
Exemplo n.º 8
0
        protected virtual NewsBase MapToNews(NewsEditModel editModel)
        {
            var activity = _newsService.Get(editModel.Id);

            activity               = Mapper.Map(editModel, activity);
            activity.MediaIds      = activity.MediaIds.Concat(_mediaHelper.CreateMedia(editModel));
            activity.PublishDate   = editModel.PublishDate.ToUniversalTime();
            activity.UnpublishDate = editModel.UnpublishDate?.ToUniversalTime();
            activity.EndPinDate    = editModel.EndPinDate?.ToUniversalTime();

            return(activity);
        }
Exemplo n.º 9
0
        protected virtual NewsBase MapToNews(NewsEditModel editModel)
        {
            var activity = _newsService.Get(editModel.Id);

            activity               = Mapper.Map(editModel, activity);
            activity.MediaIds      = activity.MediaIds.Concat(_mediaHelper.CreateMedia(editModel));
            activity.PublishDate   = editModel.PublishDate.ToUniversalTime().WithCorrectedDaylightSavingTime(editModel.PublishDate);
            activity.UnpublishDate = editModel.UnpublishDate?.ToUniversalTime().WithCorrectedDaylightSavingTime(editModel.UnpublishDate.Value);
            activity.EndPinDate    = editModel.EndPinDate?.ToUniversalTime().WithCorrectedDaylightSavingTime(editModel.EndPinDate.Value);
            activity.IsPinned      = editModel.PinAllowed && activity.IsPinned;

            return(activity);
        }
Exemplo n.º 10
0
 public override void FuncPreInitEditView(object id, ref News EditItem, ref NewsEditModel model)
 {
     if (EditItem == null)
     {
         //get the item by id
         EditItem = new NewsModel <News>().Get(id);
     }
     if (EditItem != null)
     {
         model          = new NewsEditModel();
         model.EditItem = EditItem;
     }
 }
Exemplo n.º 11
0
 public ActionResult Edit(NewsEditModel model)
 {
     if (!ModelState.IsValid)
     {
         return(Json(MVCHelper.GetJsonValidMsg(ModelState)));
     }
     if (model.ImgURL.Contains(";base64"))
     {
         string[] strs       = model.ImgURL.Split(',');
         string[] formats    = strs[0].Replace(";base64", "").Split(':');
         string   img        = strs[1];
         string   format     = formats[1];
         string[] imgFormats = { "image/png", "image/jpg", "image/jpeg", "image/bmp", "IMAGE/PNG", "IMAGE/JPG", "IMAGE/JPEG", "IMAGE/BMP" };
         byte[]   imgBytes;
         if (!imgFormats.Contains(format))
         {
             return(Json(new AjaxResult {
                 Status = "0", Msg = "请选择正确的图片格式,支持png、jpg、jpeg、png格式"
             }));
         }
         string ext = "." + format.Split('/')[1];
         try
         {
             imgBytes = Convert.FromBase64String(img);
         }
         catch (Exception ex)
         {
             return(Json(new AjaxResult {
                 Status = "0", Msg = "图片解密错误"
             }));
         }
         try
         {
             newService.Update(model.Id, model.Title, model.Contents, SaveImg(imgBytes, ext));
         }
         catch (DbEntityValidationException ex)
         {
             return(Json(new AjaxResult {
                 Status = "0", Msg = ex.Message
             }));
         }
     }
     else
     {
         newService.Update(model.Id, model.Title, model.Contents, model.ImgURL);
     }
     return(Json(new AjaxResult {
         Status = "1", Data = "/admin/news/list"
     }));
 }
Exemplo n.º 12
0
        private NewsBase MapToNews(NewsEditModel editModel)
        {
            var news = _newsService.Get(editModel.Id);

            news               = Mapper.Map(editModel, news);
            news.MediaIds      = news.MediaIds.Concat(_mediaHelper.CreateMedia(editModel, MediaFolderTypeEnum.NewsContent));
            news.PublishDate   = editModel.PublishDate.ToUniversalTime().WithCorrectedDaylightSavingTime(editModel.PublishDate);
            news.UnpublishDate = editModel.UnpublishDate?.ToUniversalTime().WithCorrectedDaylightSavingTime(editModel.UnpublishDate.Value);
            news.EndPinDate    = editModel.EndPinDate?.ToUniversalTime().WithCorrectedDaylightSavingTime(editModel.EndPinDate.Value);

            if (IsPinAllowed())
            {
                news.IsPinned = editModel.IsPinned;
            }
            return(news);
        }
Exemplo n.º 13
0
        public virtual ActionResult Edit(NewsEditModel editModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToCurrentUmbracoPage(Request.QueryString));
            }

            var cachedActivityMedias = _newsService.Get(editModel.Id).MediaIds;

            var activity = MapToNews(editModel);

            _newsService.Save(activity);

            DeleteMedia(cachedActivityMedias.Except(activity.MediaIds));

            OnNewsEdited(activity, editModel);

            string redirectUri = editModel.Links.Details;

            return(Redirect(redirectUri));
        }
        // GET: News/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            News news = db.news.Find(id);

            if (news == null)
            {
                return(HttpNotFound());
            }
            NewsEditModel model = new NewsEditModel {
                Title     = news.Title,
                Text      = news.Text,
                Id        = news.Id,
                ImagePath = news.PicturePath
            };

            return(PartialView(model));
        }
Exemplo n.º 15
0
        public IActionResult UpdateNews(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var news = _service.GetNewsById(id.Value);

            if (news == null)
            {
                return(NotFound());
            }

            var newsEditModel = new NewsEditModel(
                news.Title,
                news.Description
                );

            return(View(newsEditModel));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Add(
            NewsEditModel model,
            [FromServices] IMarkdownService markdownService)
        {
            markdownService.Render(model.MarkdownSource, out var html, out var tree);

            var news = DbContext.News.Add(new News
            {
                Source     = Encoding.UTF8.GetBytes(model.MarkdownSource),
                Title      = model.Title,
                Active     = model.Active,
                LastUpdate = DateTimeOffset.Now,
                Content    = Encoding.UTF8.GetBytes(html),
                Tree       = Encoding.UTF8.GetBytes(tree),
            });

            await DbContext.SaveChangesAsync();

            StatusMessage = "News created successfully.";
            return(RedirectToAction("Edit", new { nid = news.Entity.NewsId }));
        }
Exemplo n.º 17
0
        public IActionResult Edit(int id, NewsEditModel newsedit)
        {
            var news = myDBContent.News.Where(n => n.ID == id).FirstOrDefault();

            if (ModelState.IsValid)
            {
                news.AddTime = DateTime.Now;
                news.Title   = newsedit.Title;
                news.Content = newsedit.Content;
            }
            int v = myDBContent.SaveChanges();

            if (v > 0)
            {
                return(Redirect("/Manage/News/Index"));
            }
            else
            {
                ModelState.AddModelError("Title", "修改失败!");
            }
            return(View());
        }
Exemplo n.º 18
0
        public IActionResult NewsEdit(NewsEditModel model, int id)
        {
            News news = db.News.Find(id);

            if (ModelState.IsValid)
            {
                if (model.Description != null)
                {
                    news.Description = model.Description;
                }
                if (model.Info != null)
                {
                    news.Description = model.Description;
                }
                if (model.Name != null)
                {
                    news.Name = model.Name;
                }
                db.SaveChanges();
                return(RedirectToAction("News", "DataBases"));
            }
            ViewBag.CurrentTopic = news;
            return(View());
        }
Exemplo n.º 19
0
        public ActionResult SavePublishNews(NewsEditModel model)
        {
            SaveResult result = new SaveResult();

            if (model.Id > 0)//编辑
            {
                if (model.Version == (byte)NewsSubmitFormType.CNVersion)
                {
                    result = _component.UpdateCNVersion(new News
                    {
                        CNIntro           = model.CNIntro,
                        CNPublisher       = model.CNPublisher,
                        CNPageView        = model.CNPageView,
                        CNTitle           = model.CNTitle,
                        CNContent         = model.CNContent,
                        CNSource          = model.CNSource,
                        CNKeyword1        = model.CNKeyword1,
                        CNKeyword2        = model.CNKeyword2,
                        Status            = (NewsStatus)model.Status,
                        CNCoverPictureUrl = model.CNCoverPictureUrlList == null ? "" : model.CNCoverPictureUrlList[0],
                        Id           = model.Id,
                        NewsSetionId = model.NewsSetionId
                    });
                }
                if (model.Version == (byte)NewsSubmitFormType.ENVersion)
                {
                    result = _component.UpdateENVersion(new News
                    {
                        ENIntro           = model.ENIntro,
                        ENPublisher       = model.ENPublisher,
                        ENPageView        = model.ENPageView,
                        ENTitle           = model.ENTitle,
                        ENContent         = model.ENContent,
                        ENSource          = model.ENSource,
                        ENKeyword1        = model.ENKeyword1,
                        ENKeyword2        = model.ENKeyword2,
                        ENCoverPictureUrl = model.ENCoverPictureUrlList == null ? "" : model.ENCoverPictureUrlList[0],
                        Status            = (NewsStatus)model.Status,
                        NewsSetionId      = model.NewsSetionId,
                        Id = model.Id
                    });
                }
            }
            else //新增
            {
                News news = new News
                {
                    CNIntro           = model.CNIntro,
                    ENIntro           = model.ENIntro,
                    CNPublisher       = model.CNPublisher,
                    ENPublisher       = model.ENPublisher,
                    CNTitle           = model.CNTitle,
                    ENTitle           = model.ENTitle,
                    CNPageView        = model.CNPageView,
                    ENPageView        = model.ENPageView,
                    CNContent         = model.CNContent,
                    ENContent         = model.ENContent,
                    CNSource          = model.CNSource,
                    ENSource          = model.ENSource,
                    CNKeyword1        = model.CNKeyword1,
                    ENKeyword1        = model.ENKeyword1,
                    CNKeyword2        = model.CNKeyword2,
                    ENKeyword2        = model.ENKeyword2,
                    Status            = (NewsStatus)model.Status,
                    CreateTime        = DateTime.UtcNow,
                    ModifyTime        = null,
                    AccountsId        = AccountInfo.Id,
                    CNCoverPictureUrl = model.CNCoverPictureUrlList == null ? "" : model.CNCoverPictureUrlList[0],
                    ENCoverPictureUrl = model.ENCoverPictureUrlList == null ? "" : model.ENCoverPictureUrlList[0],
                    NewsSetionId      = model.NewsSetionId
                };
                result = new NewsComponent().Create(news);
            }
            return(Json(result.toJson()));
        }
Exemplo n.º 20
0
        private async Task OnNewsEditedAsync(NewsBase news, NewsEditModel model)
        {
            await _activityTagsHelper.ReplaceTagsAsync(news.Id, model.TagIdsData);

            await ResolveMentionsAsync(model.Description, news);
        }
Exemplo n.º 21
0
 protected virtual void OnNewsEdited(NewsBase news, NewsEditModel model)
 {
 }
Exemplo n.º 22
0
 private void Prepare(int?id)
 {
     Input = _newsService.GetForEdit(id);
 }