public static NewsGallery NewsGalleryModelToNewsGallery(NewsGalleryModel galleryModel) { return new NewsGallery { Caption = galleryModel.Caption, Id = galleryModel.Id, Photo = galleryModel.Photo, NewsId = galleryModel.NewsId }; }
internal void UploadNewsImages(int id, HttpRequestBase Request) { //Loop through each uploaded file foreach (string fileKey in Request.Files.Keys) { HttpPostedFileBase file = Request.Files[fileKey]; if (file.ContentLength <= 0) continue; //Skip unused file controls. //Get the physical path for the uploads folder and make sure it exists string uploadFolder = HttpContext.Current.Server.MapPath("~/Content/uploads/news/gallery"); if (!Directory.Exists(uploadFolder)) Directory.CreateDirectory(uploadFolder); string filePath = Path.Combine(uploadFolder, Path.GetFileName(file.FileName)); file.SaveAs(filePath); // string filenameWithoutExt = Path.Combine(uploadFolder, System.Guid.NewGuid().ToString()); //string fileName = System.Guid.NewGuid() + ".jpg"; NewsGalleryModel galleryModel = new NewsGalleryModel { Caption = string.Empty, Photo = string.Format("..\\..\\Content\\uploads\\news\\gallery\\{0}", file.FileName), NewsId = id, }; NewsGallery gallery = GalleryMapper.NewsGalleryModelToNewsGallery(galleryModel); //Save photo entry to database repo.AddNewsGallery(gallery); } }