/// <summary> /// Create a new SlideshowItem object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="date">Initial value of the Date property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="text">Initial value of the Text property.</param> /// <param name="fileId">Initial value of the FileId property.</param> public static SlideshowItem CreateSlideshowItem(global::System.Int32 id, global::System.DateTime date, global::System.String title, global::System.String text, global::System.Int32 fileId) { SlideshowItem slideshowItem = new SlideshowItem(); slideshowItem.Id = id; slideshowItem.Date = date; slideshowItem.Title = title; slideshowItem.Text = text; slideshowItem.FileId = fileId; return slideshowItem; }
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); }
/// <summary> /// Deprecated Method for adding a new object to the SlideshowItemSet EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToSlideshowItemSet(SlideshowItem slideshowItem) { base.AddObject("SlideshowItemSet", slideshowItem); }