Пример #1
0
        internal void UploadProjectImages(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/projects/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";

                ProjectGalleryModel galleryModel = new ProjectGalleryModel
                {
                    Caption = string.Empty,
                    Photo = string.Format("..\\..\\Content\\uploads\\projects\\gallery\\{0}", file.FileName),
                    ProjectId = id,
                };

                ProjectGallery gallery = GalleryMapper.ProjectGalleryModelToProjectGallery(galleryModel);

                //Save photo entry to database
                repo.AddProjectGallery(gallery);

            }
        }
Пример #2
0
 public static ProjectGallery ProjectGalleryModelToProjectGallery(ProjectGalleryModel galleryModel)
 {
     return new ProjectGallery
     {
         Caption = galleryModel.Caption,
         Id = galleryModel.Id,
         Photo = galleryModel.Photo,
         ProjectId = galleryModel.ProjectId
     };
 }