public SlideShowPage() { InitializeComponent(); ApplicationBar.IsVisible = false; ViewModelLocator viewModelLocator = App.Current.Resources["Locator"] as ViewModelLocator; _articleViewModel = viewModelLocator.SlideshowViewModel; }
public ActionResult Update(SlideshowViewModel viewModel, HttpPostedFileBase file) { if (!ModelState.IsValid) { return(View("SlideshowForm", viewModel)); } if (file != null) { viewModel.Photo = UploadPhoto(file); } _slideshowService.Update(Mapper.Map <SlideshowDto>(viewModel)); return(RedirectToAction("Index")); }
public ActionResult EditSlide(int id) { var slide = slideshowRepository.GetById(id); if (slide == null) { TempData[Const.ActionErrorInfo] = "Слайд не найден"; return RedirectToAction("Committees"); } var viewModel = new SlideshowViewModel { Id = id, Text = slide.Text, Title = slide.Title, SlideshowImagePath = slide.File.FileName }; return View(viewModel); }
public ActionResult EditSlide(SlideshowViewModel slideshow, HttpPostedFileBase file) { if(ModelState.IsValid) { using(new UnitOfWork(_currentContext)) { var exising = slideshowRepository.GetById(slideshow.Id.Value); if (file != null) { //upload file first var ticks = DateTime.Now.Ticks; var fileName = String.Format("slideshow-{0}", ticks) + Path.GetExtension(file.FileName); var absoluteTempPath = Server.MapPath("~/Content/images/uploads/temp/"); var absolutePath = Server.MapPath("~/Content/images/uploads/slideshow/"); var fullVirtualPath = "~/Content/images/uploads/slideshow/" + fileName; //create a temp file first, then compress it FileUploader.UploadFile(file, fileName, absoluteTempPath); var encoder = new ImageEncoder(); encoder.Compress(absoluteTempPath + fileName, absolutePath + fileName, 620, 465); //after compressing deleting original file FileUploader.DeleteFile(absoluteTempPath + fileName); var slideshowImage = new File() { FileName = fullVirtualPath, FilePurposeId = (int) FilePurposes.Slideshow }; //delete the old file FileUploader.DeleteFile(Server.MapPath(exising.File.FileName)); filesRepository.Remove(exising.FileId); exising.File = slideshowImage; } exising.Title = slideshow.Title; exising.Text = slideshow.Text; exising.Date = DateTime.Now; } TempData[Const.ActionResultInfo] = "Слайд успешно отредактирован"; return RedirectToAction("Slideshow"); } TempData[Const.ActionErrorInfo] = "Ошибка редактирования слайда. Проверьте правильность введенных данных"; return View(slideshow); }
public ActionResult AddSlide(SlideshowViewModel slideshow, HttpPostedFileBase file) { if(ModelState.IsValid) { using (new UnitOfWork(_currentContext)) { //upload file first var ticks = DateTime.Now.Ticks; var fileName = String.Format("slideshow-{0}", ticks) + Path.GetExtension(file.FileName); var absoluteTempPath = Server.MapPath("~/Content/images/uploads/temp/"); var absolutePath = Server.MapPath("~/Content/images/uploads/slideshow/"); var fullVirtualPath = "~/Content/images/uploads/slideshow/" + fileName; //create a temp file first, then compress it FileUploader.UploadFile(file, fileName, absoluteTempPath); var encoder = new ImageEncoder(); encoder.Compress(absoluteTempPath + fileName, absolutePath + fileName, 620, 465); //after compressing deleting original file FileUploader.DeleteFile(absoluteTempPath + fileName); var slideshowImage = new File() { FileName = fullVirtualPath, FilePurposeId = (int) FilePurposes.Slideshow }; var slideshowItem = new SlideshowItem { Title = slideshow.Title, Text = slideshow.Text, Date = DateTime.Now, File = slideshowImage }; slideshowRepository.Add(slideshowItem); } TempData[Const.ActionResultInfo] = "Слайд успешно добавлен"; return RedirectToAction("Slideshow"); } TempData[Const.ActionErrorInfo] = "Невозможно добавить слайд. Проверьте правильность введенных данных"; return View(slideshow); }