Exemplo n.º 1
0
        public ActionResult CreateNews(News createdNews, IFormFile UploadImg)
        {
            if (ModelState.IsValid)
            {
                if (UploadImg != null && UploadImg.Length > 0)
                {
                    string ImgPath = Path.Combine(env.WebRootPath + "\\imageUploads\\NewsImg", UploadImg.FileName);
                    UploadImg.CopyTo(new FileStream(ImgPath, FileMode.Create));
                    createdNews.Image = UploadImg.FileName;

                    bool successfullyCreatingNews = DAL.CreateNews(createdNews);
                    if (successfullyCreatingNews)
                    {
                        return(RedirectToAction("GetAllNews"));
                    }
                    else
                    {
                        return(View(createdNews));
                    }
                }
                else
                {
                    ViewBag.Message = "You have not specified a file yet ...";
                }
            }
            return(View(createdNews));
        }
Exemplo n.º 2
0
        public ActionResult CreateNews(News createdNews, HttpPostedFileBase UploadImg)
        {
            if (ModelState.IsValid)
            {
                if (UploadImg != null && UploadImg.ContentLength > 0)
                {
                    string ImgPath = Path.Combine(Server.MapPath("~/imageUploads/NewsImg"), UploadImg.FileName);
                    UploadImg.SaveAs(ImgPath);
                    createdNews.Image = UploadImg.FileName;

                    bool successfullyCreatingNews = DAL.CreateNews(createdNews);
                    if (successfullyCreatingNews)
                    {
                        return(RedirectToAction("GetAllNews"));
                    }
                    else
                    {
                        return(View(createdNews));
                    }
                }
                else
                {
                    ViewBag.Message = "You have not specified a file yet ...";
                }
            }
            return(View(createdNews));
        }