public ActionResult DeleteConfirmed(int id) { NewsPhotoDetail newsPhoto = db.NewsPhotoDetails.Find(id); db.NewsPhotoDetails.Remove(newsPhoto); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "NewsPhotoID,NewsID,PhotoLocation")] NewsPhotoDetail newsPhoto) { if (ModelState.IsValid) { db.Entry(newsPhoto).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.NewsID = new SelectList(db.News, "NewsID", "Title", newsPhoto.NewsID); return(View(newsPhoto)); }
public ActionResult Create([Bind(Include = "NewsPhotoID,NewsID,PhotoLocation")] NewsPhotoDetail newsPhoto) { if (ModelState.IsValid) { db.NewsPhotoDetails.Add(newsPhoto); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.NewsID = new SelectList(db.News, "NewsID", "Title", newsPhoto.NewsID); return(View(newsPhoto)); }
// GET: NewsPhotos/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NewsPhotoDetail newsPhoto = db.NewsPhotoDetails.Find(id); if (newsPhoto == null) { return(HttpNotFound()); } return(View(newsPhoto)); }
// GET: NewsPhotos/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NewsPhotoDetail newsPhoto = db.NewsPhotoDetails.Find(id); if (newsPhoto == null) { return(HttpNotFound()); } ViewBag.NewsID = new SelectList(db.News, "NewsID", "Title", newsPhoto.NewsID); return(View(newsPhoto)); }
public ActionResult Create([Bind(Include = "Title,Content,PostDate,")] News news) { CalculationHelper calculation = new CalculationHelper(); FileUploadValidation uploadedFiles = new FileUploadValidation(); //tikrinama ar is vis prisegtas failas if (Request.Files[0].ContentLength > 0) { uploadedFiles.filesize = 2000; uploadedFiles.ValidateUploadedUserFile(Request.Files, SuportedTypes.Images); } //-------------- if (ModelState.IsValid && uploadedFiles.IsValid) { string uploadDirectoryYears = Path.Combine(Request.PhysicalApplicationPath, @"Photo\News\" + news.PostDate.Year.ToString()); string uploadDirectoryMonth = Path.Combine(uploadDirectoryYears, news.PostDate.Month.ToString()); string uploadDirectory = Path.Combine(uploadDirectoryMonth, calculation.ChangeNewsTitle(news.Title.ToUpper())); List <NewsPhotoDetail> photoDetails = new List <NewsPhotoDetail>(); for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (file != null && file.ContentLength > 0) { var fileName = i + 1 + Path.GetExtension(file.FileName); //Path.GetFileName(file.FileName); NewsPhotoDetail photoDetail = new NewsPhotoDetail() { FileName = fileName, NewsID = news.NewsID, PhotoLocation = uploadDirectory }; photoDetails.Add(photoDetail); if (!Directory.Exists(uploadDirectory)) { Directory.CreateDirectory(uploadDirectory); } var path1 = Path.Combine(Server.MapPath("~/Photo/News/"), photoDetail.FileName); var path = Path.Combine(uploadDirectory, photoDetail.FileName); file.SaveAs(path); } } news.NewsPhotoDetails = photoDetails; news.Title = news.Title.ToUpper(); db.News.Add(news); db.SaveChanges(); //return RedirectToAction("Index"); //pranesimas po sekmingo patalpinimo ViewBag.ResultMessage = uploadedFiles.Message; return(View()); } //------------------------ //if (ModelState.IsValid) //{ // var a = Request.Files[0].FileName; // var b = Request.Files[1]; // var c = Request.Files[2]; // news.PostDate = news.PostDate.Add(DateTime.Now.TimeOfDay); // news.Content = HttpUtility.HtmlEncode(news.Content); // db.News.Add(news); // db.SaveChanges(); // return RedirectToAction("Index"); //} ViewBag.ResultMessage = uploadedFiles.Message; return(View(news)); }