public ActionResult Create() { DestinationDao destinationDao = new DestinationDao(); IList <Destination> destinations = destinationDao.GetAll(); ViewBag.Categories = destinations; return(View()); }
public ActionResult Add(Tour tour, HttpPostedFileBase picture, int categoryId) { DestinationDao destinationDao = new DestinationDao(); IList <Destination> destinations = destinationDao.GetAll(); ViewBag.Categories = destinations; if (ModelState.IsValid) { if (picture != null) { if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png") { Image image = Image.FromStream(picture.InputStream); Guid guid = Guid.NewGuid(); string imageName = guid.ToString() + ".jpg"; Image smallImage = ImageHelper.ScaleImage(image, 1200, 1200); Bitmap b = new Bitmap(smallImage); b.Save(Server.MapPath("~/uploads/book/" + imageName), ImageFormat.Jpeg); smallImage.Dispose(); b.Dispose(); tour.ImageName = imageName; } } Destination destination = destinationDao.GetById(categoryId); tour.Destination = destination; if (tour.CurrentCapacity == null) { tour.CurrentCapacity = 0; } if (tour.Priority == null) { tour.Priority = 0; } TourDao tourDao = new TourDao(); tourDao.Create(tour); TempData["message-success"] = "Zajezd byl uspesne pridan"; } else { return(View("Create", tour)); } return(RedirectToAction("Index")); }
public ActionResult Edit(int id) { TourDao bookDao = new TourDao(); DestinationDao bookCategoryDao = new DestinationDao(); Tour b = bookDao.GetById(id); ViewBag.Categories = bookCategoryDao.GetAll(); return(View(b)); }
public ActionResult Update(Tour tour, HttpPostedFileBase picture, int categoryId) { try { TourDao bookDao = new TourDao(); DestinationDao bookCategoryDao = new DestinationDao(); Destination bookCategory = bookCategoryDao.GetById(categoryId); tour.Destination = bookCategory; if (picture != null) { if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png") { Image image = Image.FromStream(picture.InputStream); Guid guid = Guid.NewGuid(); string imageName = guid.ToString() + ".jpg"; //picture.SaveAs(Server.MapPath("~/uploads/tour/" + picture.FileName)); Image smallImage = ImageHelper.ScaleImage(image, 1200, 1200); Bitmap b = new Bitmap(smallImage); b.Save(Server.MapPath("~/uploads/book/" + imageName), ImageFormat.Jpeg); smallImage.Dispose(); b.Dispose(); //smazat stary soubor System.IO.File.Delete(Server.MapPath("~/uploads/book/" + tour.ImageName)); tour.ImageName = imageName; } } bookDao.Update(tour); TempData["message-success"] = "Zajezd " + tour.Name + " byl upraven"; } catch (Exception) { throw; } return(RedirectToAction("Index", "Tours")); }
public ActionResult AddCategory(Destination bookCategory) { if (ModelState.IsValid) { DestinationDao bookCategoryDao = new DestinationDao(); bookCategoryDao.Create(bookCategory); TempData["message-success"] = "Destinace byla uspesne pridana"; ViewBag.Categories = bookCategoryDao.GetAll(); } else { return(View("CreateCategory", bookCategory)); } return(RedirectToAction("Create")); }