public ActionResult NewArticle(Article article, int catid = 0) { if (ModelState.IsValid) { article.AddArticle(article, catid); } return(View(article)); }
public IActionResult AddArticle([FromBody] Article article) { int success = Article.AddArticle(article); if (success == -1) { return(NotFound()); } return(Ok()); }
public async Task <IActionResult> AddArticlePost(string titre, string text, int idCategory, IFormFile media) { ViewBag.NbreVisitUnique = GetVisitIP(); ViewBag.NbrePagesVues = GetPageVues(); UserConnect(ViewBag); CategoryArticle c = new CategoryArticle { Id = idCategory }; Membres m = new Membres { IdMembre = Convert.ToInt32(ViewBag.Id) }; Article a = new Article { Titre = titre, Texte = text, Categorie = c, Auteur = m, Date = DateTime.Now }; a = a.AddArticle(); string NumeroUnique = Guid.NewGuid().ToString("N"); var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/MediasArticles", a.Id.ToString() + "-" + NumeroUnique + media.FileName); var stream = new FileStream(path, FileMode.Create); await media.CopyToAsync(stream); MediaArticle mediaArticle = new MediaArticle { Url = "images/MediasArticles/" + a.Id.ToString() + "-" + NumeroUnique + media.FileName, IdArticle = a.Id }; mediaArticle.AddMediaArticle(); ArticlesCategoriesViewModel viewModel = new ArticlesCategoriesViewModel { Categories = c.GetAllCategory(), Articles = a.GetAllArticles(null, null) }; return(View("ListArticles", viewModel)); }
protected void ButtonSubmit_Click(object sender, EventArgs e) { if (Validation()) { String title = TextboxTitle.Text.ToString(); int views = 0; int likes = 0; int comments = 0; String description = TextboxDescription.Text.ToString(); String image = ""; var dateAndTime = DateTime.Now; String lastupdated = dateAndTime.ToShortDateString(); String dateposted = dateAndTime.ToShortDateString(); String email = Session["email"].ToString(); Profiles prof = new Profiles(); prof = prof.GetProfileById(email); String author = prof.Fname.ToString(); String link = TextboxLink.Text.ToString(); Boolean deleted = false; if (UploadImage.HasFile) { string filename = Path.GetFileName(UploadImage.FileName); UploadImage.SaveAs(Server.MapPath("img/articleImages/") + filename); image = ("img/articleImages/" + filename); } else { image = "img/articleImages/DefaultImage.jpg"; } //Instantiate object Article art = new Article(title, views, likes, comments, description, image, dateposted, author, link, lastupdated, deleted); int insCnt = art.AddArticle(); Response.Redirect("LearnAdmin.aspx"); } }
public IActionResult RegisterArticle(string title, string description, decimal?price, int?idCategory, IFormFile imageArticle) { UserConnect(ViewBag); List <string> message = new List <string>(); Article a = new Article { Title = title, Description = description, Price = price, IdCategory = idCategory }; if (idCategory == null) { message.Add("Merci de saisir une catégorie"); } if (title == null) { message.Add("Merci de saisir le titre de l'article"); } if (description == null) { message.Add("Merci de saisir une descriptione"); } if (price == null) { message.Add("Merci de saisir le prix de l'article"); } if (imageArticle == null) { //a.UrlImage = "images/default.png"; message.Add("Merci de selectionner une image"); } if (message.Count > 0) { ViewBag.errors = message; ViewBag.Category = Category.GetCategories(); List <Article> articles = Article.GetArticles(); ViewBag.Article = articles; articles.ForEach(c => { c.UrlImage = $"{Request.Scheme}://{Request.Host.Value}/{c.UrlImage}"; }); //return View("ArticleAdmin"); } else { ViewBag.Category = Category.GetCategories(); string img = Guid.NewGuid().ToString() + "-" + imageArticle.FileName; string pathToUpload = Path.Combine(_env.WebRootPath, "images", img); FileStream stream = System.IO.File.Create(pathToUpload); imageArticle.CopyTo(stream); stream.Close(); a.UrlImage = "images/" + img; a.IdCategory = idCategory; a.AddArticle(a); ViewBag.validation = "L'article " + a.Title + " a été ajouté"; List <Article> articles = Article.GetArticles(); ViewBag.Article = articles; articles.ForEach(c => { c.UrlImage = $"{Request.Scheme}://{Request.Host.Value}/{c.UrlImage}"; }); } return(View("ArticleAdmin")); }