public ActionResult Create() { ImageSetVM vm = new ImageSetVM { Images = UOW.Images.GetAll() }; return(View("Edit", vm)); }
public IEnumerable <ImageSetVM> Get() { List <ImageSetVM> imageSets = new List <ImageSetVM>(); //base directory ImageSetVM imageSet = new ImageSetVM() { name = "Root", images = new List <string>() }; foreach (string file in Directory.GetFiles($"wwwroot{Path.DirectorySeparatorChar}cards")) { imageSet.images.Add($"/cards/{Path.GetFileName(file)}"); } imageSets.Add(imageSet); //downloads directory as second set imageSet = new ImageSetVM() { name = "Downloads", images = new List <string>() }; foreach (string file in Directory.GetFiles($"wwwroot{Path.DirectorySeparatorChar}cards{Path.DirectorySeparatorChar}downloads")) { imageSet.images.Add($"/cards/downloads/{Path.GetFileName(file)}"); } imageSets.Add(imageSet); //subdirectories foreach (string directory in Directory.GetDirectories($"wwwroot{Path.DirectorySeparatorChar}cards")) { string directoryName = Path.GetFileName(directory); if (directoryName.Equals("downloads")) { continue; //skip downloads folder } imageSet = new ImageSetVM() { name = directoryName, images = new List <string>() }; foreach (string file in Directory.GetFiles(directory)) { imageSet.images.Add($"/cards/{directoryName}/{Path.GetFileName(file)}"); } imageSets.Add(imageSet); } return(imageSets); }
public ActionResult Edit([Bind(Prefix = "ImageSet")] ImageSet imageSet, [Bind(Include = "Images")] List <Guid> images) { ImageSet dbImageSet = UOW.ImageSets.GetById(imageSet.ImageSetId); if (dbImageSet != null) { if (images != null) { dbImageSet.Name = imageSet.Name; dbImageSet.ImageId = imageSet.ImageId; var items = UOW.ImageSetItems.GetByImageSetId(imageSet.ImageSetId); foreach (var item in items) { UOW.ImageSetItems.Delete(item); } List <ImageSetItem> newItemSet = new List <ImageSetItem>(); byte pos = 1; foreach (Guid item in images) { newItemSet.Add(new ImageSetItem { ImageSetItemId = Guid.NewGuid(), ImageId = item, Position = pos++, ImageSetId = dbImageSet.ImageSetId }); } dbImageSet.ImageSetItems = newItemSet; UOW.Commit(); imageSet = dbImageSet; } else { ModelState.AddModelError(string.Empty, "ImageSet must be associated with one or more set images."); } } else { return(HttpNotFound()); } ImageSetVM vm = new ImageSetVM { ImageSet = imageSet, Images = UOW.Images.GetAll() }; return(View(vm)); }
public ActionResult Create([Bind(Prefix = "ImageSet")] ImageSet imageSet, [Bind(Include = "Images")] List <Guid> images) { if (ModelState.IsValid) { if (images != null) { ImageSet newImageSet = new ImageSet(); newImageSet.ImageSetId = Guid.NewGuid(); newImageSet.Name = imageSet.Name; newImageSet.ImageId = imageSet.ImageId; //UOW.ImageSetItems.DeleteByImageSetId(newImageSet.ImageSetId); List <ImageSetItem> newItemSet = new List <ImageSetItem>(); byte pos = 1; foreach (Guid item in images) { newItemSet.Add(new ImageSetItem { ImageSetItemId = Guid.NewGuid(), ImageId = item, Position = pos++, ImageSetId = newImageSet.ImageSetId }); } newImageSet.ImageSetItems = newItemSet; UOW.ImageSets.Add(newImageSet); UOW.Commit(); imageSet = newImageSet; } else { ModelState.AddModelError(string.Empty, "ImageSet must be associated with one or more set images."); } } ImageSetVM vm = new ImageSetVM { ImageSet = imageSet, Images = UOW.Images.GetAll() }; return(View("Edit", vm)); }
public ActionResult Details(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ImageSet imageSet = UOW.ImageSets.GetById(id); if (imageSet == null) { return(HttpNotFound()); } ImageSetVM vm = new ImageSetVM { ImageSet = imageSet }; return(View(vm)); }