Beispiel #1
0
        public IActionResult EditArticle(int articleId)
        {
            ArticleModel     article = _articleService.GetArticleByArticleId(articleId);
            EditArticleModel model   = new EditArticleModel(article);

            return(View(model));
        }
        public async Task <IActionResult> Edit(int id, EditArticleModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            if (inputModel.Image != null)
            {
                if (inputModel.Image.ContentType != "image/jpeg" &&
                    inputModel.Image.ContentType != "image/png" &&
                    inputModel.Image.ContentType != "svg+xml")
                {
                    this.ModelState.AddModelError(string.Empty, InvalidImageType);

                    return(this.View(inputModel));
                }

                inputModel.ImageUrl = await this.cloudinaryService.UploadAsync(inputModel.Image, inputModel.Image.FileName);
            }

            var articleServiceModel = AutoMapperConfig.MapperInstance.Map <EditArticleServiceModel>(inputModel);

            await this.articlesService.EditAsync(id, articleServiceModel);

            return(this.RedirectToAction("Details", new { id = id }));
        }
Beispiel #3
0
        public ActionResult Edit(EditArticleModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.IsNew())
                {
                    CreateArticleStatus status = ArticleService.Create(model.Title, model.Content, CultureInfo.GetCultureInfo(model.Culture), UserContext.Account);
                    if (status == CreateArticleStatus.Created)
                    {
                        ShowMessage(String.Format((L)"Article '{0}' created.", model.Title));
                        return RedirectToAction("index");
                    }
                }
                else
                {
                    UpdateArticleStatus status = ArticleService.Update(model.ID, model.Title, model.Content);
                    switch (status)
                    {
                        case UpdateArticleStatus.Updated:
                            ShowMessage(String.Format((L)"Article '{0}' updated.", model.Title));
                            break;
                        case UpdateArticleStatus.NoSuchArticle:
                            ShowMessage((L)"No such article!", HtmlMessageType.Error);
                            break;
                    }
                    return RedirectToAction("index");
                }
            }

            return View(model);
        }
Beispiel #4
0
        public ActionResult Edit(EditArticleModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.IsNew())
                {
                    CreateArticleStatus status = ArticleService.Create(model.Title, model.Content, CultureInfo.GetCultureInfo(model.Culture), UserContext.Account);
                    if (status == CreateArticleStatus.Created)
                    {
                        ShowMessage(String.Format((L)"Article '{0}' created.", model.Title));
                        return(RedirectToAction("index"));
                    }
                }
                else
                {
                    UpdateArticleStatus status = ArticleService.Update(model.ID, model.Title, model.Content);
                    switch (status)
                    {
                    case UpdateArticleStatus.Updated:
                        ShowMessage(String.Format((L)"Article '{0}' updated.", model.Title));
                        break;

                    case UpdateArticleStatus.NoSuchArticle:
                        ShowMessage((L)"No such article!", HtmlMessageType.Error);
                        break;
                    }
                    return(RedirectToAction("index"));
                }
            }

            return(View(model));
        }
Beispiel #5
0
        public ActionResult EditArticle(EditArticleModel edited, string[] tags, string imageCondition)
        {
            if (!ModelState.IsValid)
            {
                return(View(edited));
            }
            var baseArticle = repo.GetItem(edited.Id);

            if (baseArticle == null || baseArticle.UserId != User.Identity.GetUserId <int>())
            {
                return(HttpNotFound());
            }

            var changesExist = false;

            if (imageCondition == "Empty")
            {
                baseArticle.Image = "Empty";
                changesExist      = true;
            }


            if (edited.Image != null)
            {
                var fileHelper = new FileHelper();
                var isChanged  = fileHelper.SaveFIle(Server.MapPath(ConfigurationManager.AppSettings["ArticleImagesFolder"]), edited.Image, baseArticle.Id);
                if (isChanged)
                {
                    baseArticle.Image = edited.Image.FileName;
                    changesExist      = true;
                }
            }
            if (baseArticle.Title != edited.Title)
            {
                baseArticle.Title = edited.Title;
                changesExist      = true;
            }
            if (baseArticle.ShortDescription != edited.ShortDescription)
            {
                baseArticle.ShortDescription = edited.ShortDescription;
                changesExist = true;
            }
            if (baseArticle.FullDescription != edited.FullDescription)
            {
                baseArticle.FullDescription = edited.FullDescription;
                changesExist = true;
            }
            baseArticle.Tags.Clear();
            if (tags != null)
            {
                IEnumerable <Tag> newTags = TagsHelper.CreateTagList(tags, tagRepo);
                TagsHelper.SetTagForModel(baseArticle, newTags);
                changesExist = true;
            }
            if (changesExist)
            {
                repo.Save(baseArticle);
            }
            return(RedirectToAction("Article", new { Title = edited.Title, Id = edited.Id }));
        }
        public ActionResult AddAttach(HttpPostedFileBase file, EditArticleModel model)
        {
            if (file != null)
            {
                string attach = System.IO.Path.GetFileName(file.FileName);
                string dir    = Server.MapPath("~/images/attach");
                string path   = System.IO.Path.Combine(dir, attach);

                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                int i = 0;
                if (HttpContext.Session["ListAttach" + i] != null)
                {
                    while (HttpContext.Session["ListAttach" + i] != null)
                    {
                        i++;
                    }
                }
                HttpContext.Session["ListAttach" + i] = attach;
                file.SaveAs(path);
            }
            return(RedirectToAction("EditArticle", "Articles", model));
        }
Beispiel #7
0
        public ActionResult EditArticle(int id = 0)
        {
            if (id < 1)
            {
                return(HttpNotFound());
            }
            var article = repo.GetItem(id);
            EditArticleModel editArticle = new EditArticleModel(article);

            editArticle.AllTags = tagRepo.GetAllTags();
            if (article == null || article.UserId != User.Identity.GetUserId <int>())
            {
                return(HttpNotFound());
            }
            return(View(editArticle));
        }
        public ActionResult EditArticle(EditArticleModel model, HttpPostedFileBase file)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = true;

            switch (result)
            {
            case true:
                DBO.Article article = new DBO.Article {
                    Title = model.Title, Content = model.Content, Validated = false, CreatedDate = DateTime.Now
                };
                var idCreator = HttpContext.Session["UserID"];
                if (idCreator != null)
                {
                    article.IdCreator = (long)idCreator;
                }
                BusinessManagement.Article.CreateArticle(ref article);

                if (file != null)
                {
                    string pic  = System.IO.Path.GetFileName(file.FileName);
                    string dir  = Server.MapPath("~/images/article");
                    string path = System.IO.Path.Combine(dir, pic);

                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    // file is uploaded
                    file.SaveAs(path);
                    DBO.ArticleImage image = new DBO.ArticleImage();
                    image.ImagePath = path;
                    image.Name      = pic;
                    image.IdArticle = article.Id;
                    BusinessManagement.ArticleImage.CreateArticleImage(image);
                }
                string dirAttach = Server.MapPath("~/images/attach");
                int    i         = 0;
                if (HttpContext.Session["ListAttach" + i] != null)
                {
                    while (HttpContext.Session["ListAttach" + i] != null)
                    {
                        DBO.ArticleAttach articleAttach = new DBO.ArticleAttach();
                        articleAttach.Name      = (string)HttpContext.Session["ListAttach" + i];
                        articleAttach.FilePath  = Path.Combine(dirAttach, articleAttach.Name);
                        articleAttach.IdArticle = article.Id;
                        BusinessManagement.ArticleAttach.CreateArticleAttach(articleAttach);
                        i++;
                    }
                }


                return(RedirectToAction("Submit", "Articles"));

            case false:
                ModelState.AddModelError("", "Insertion d'article invalide");
                return(View(model));

            default:
                ModelState.AddModelError("", "Insertion d'article invalide");
                return(View(model));
            }
        }