Exemplo n.º 1
0
 public static EventGallery EventGalleryModelToEventGallery(EventsGalleryModel galleryModel)
 {
     return new EventGallery
     {
         Caption = galleryModel.Caption,
         Id = galleryModel.Id,
         Photo = galleryModel.Photo,
         EventId = galleryModel.EventId
     };
 }
Exemplo n.º 2
0
        internal void UploadEventImages(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/events/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";

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

                EventGallery gallery = GalleryMapper.EventGalleryModelToEventGallery(galleryModel);

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

            }
        }