public ActionResult UploadFilesByPlanetId(int planetId) { IPlanetRepo pr = new PlanetRepo(); var files = Request.Files.AllKeys.Select(fileName => Request.Files[fileName]).Where(file => file.ContentLength > 0).ToList(); PlanetViewModel pvm = pr.GetById(planetId); if (User.Identity.Name != pvm.Uploader) return Json(new {Message = "You are not the original uploader of this Planet."}); foreach (var file in files) { var fileName = Guid.NewGuid() + Path.GetExtension(file.FileName); var virtualPath = "~/Content/img/" + DateTime.Today.ToString("MMddyyyy"); var subPath = Server.MapPath(virtualPath); if (!Directory.Exists(subPath)) { Directory.CreateDirectory(subPath); } var path = Path.Combine(subPath, fileName); try { file.SaveAs(path); } catch (Exception e) { continue; } IFileSystemRepo fsr = new FileSystemRepo(); fsr.SaveFileDataByPlanetId( Path.Combine(virtualPath.Replace("~/", "/").Replace("\\\\", "/"), fileName), fileName, planetId); } return Json(new { Message = string.Empty }); }
// GET: Planet/Details/5 public ActionResult Details(int id) { IPlanetRepo pr = new PlanetRepo(); IStarSystemRepo ssr = new StarSystemRepo(); IFileSystemRepo fsr = new FileSystemRepo(); var planet = pr.GetById(id); planet.StarSystem = ssr.GetById(planet.StarSystem.Id); planet.PlanetImagePaths = new Dictionary<string, string>(); foreach (var item in fsr.GetFileDataByPlanetId(id)) { planet.PlanetImagePaths.Add(item.Path.Replace("\\", "/"), item.Name); } return View(planet); }
public ActionResult Edit(int id) { IPlanetRepo pr = new PlanetRepo(); var pvm = pr.GetById(id); ViewBag.SystemSelect = SystemSelect(); ViewBag.ClassSelect = ClassSelect(); ViewBag.CategorySelect = CategorySelect(); return View(pvm); }