Exemplo n.º 1
0
        // GET: All
        public ActionResult All()
        {
            IStarSystemRepo ssr = new StarSystemRepo();
            List<StarSystemViewModel> starSystems = ssr.GetAll().ToList();

            var json = Json(starSystems);
            json.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return json;
        }
Exemplo n.º 2
0
        // GET: StarSystem/Details/5
        public ActionResult Details(int id)
        {
            IStarSystemRepo ssr = new StarSystemRepo();
            IPlanetRepo pr = new PlanetRepo();
            DetailsViewModel dvm = new DetailsViewModel();

            var planets = pr.GetByStarSystemId(id).ToList();
            var starSystem = ssr.GetById(id);
            dvm.StarSystem = starSystem;
            dvm.Planets = planets;
            return View(dvm);
        }
Exemplo n.º 3
0
        public ActionResult Create(StarSystemViewModel ssvm)
        {
            try
            {

                IStarSystemRepo ssr = new StarSystemRepo();
                ssr.Create(ssvm);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Exemplo n.º 4
0
        public ActionResult ImportFiles()
        {
            IFileSystemRepo fsr = new FileSystemRepo();
            IStarSystemRepo ssr = new StarSystemRepo();
            var files = Request.Files.AllKeys.Select(fileName => Request.Files[fileName]).Where(file => file.ContentLength > 0).ToList();
            List<string> pathNames = new List<string>();
            foreach (var file in files)
            {
                var fileName = Guid.NewGuid() + Path.GetExtension(file.FileName);
                var virtualPath = "~/Content/netlogs/" + 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;
                }

                fsr.SaveFileData(Path.Combine(virtualPath.Replace("~/", "/").Replace("\\", "/"), fileName), fileName);
                pathNames.Add(path);
            }
            foreach (var path in pathNames)
            {
                List<NetLog> nlList =
                    NetLogTranslator.RawNetLogToNetLogs(path)
                        .GroupBy(nl => nl.SystemName)
                        .Select(lst => lst.First()).ToList();
                foreach (var nl in nlList)
                {
                    var ssvm = new StarSystemViewModel
                    {
                        Name = nl.SystemName,
                        Uploader = User.Identity.Name
                    };
                    ssr.Create(ssvm);
                }
            }
            return Json(new { Message = string.Empty });
        }
Exemplo n.º 5
0
 // 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);
 }
Exemplo n.º 6
0
 protected SelectList SystemSelect()
 {
     IStarSystemRepo ssr = new StarSystemRepo();
     Dictionary<int, string> ssList = ssr.GetAll().ToDictionary(ss => ss.Id, ss => ss.Name);
     return new SelectList(ssList, "Key", "Value");
 }
Exemplo n.º 7
0
 // GET: Planet
 public ActionResult Index()
 {
     IPlanetRepo pr = new PlanetRepo();
     IStarSystemRepo ssr = new StarSystemRepo();
     var planets = pr.GetAll().ToList();
     var starSystems = ssr.GetAll().ToList();
     foreach (var planet in planets)
     {
         planet.StarSystem = starSystems.Single(ss => ss.Id == planet.StarSystem.Id);
     }
     return View(planets);
 }
Exemplo n.º 8
0
        public ActionResult Edit(int id)
        {
            IStarSystemRepo ssr = new StarSystemRepo();
            IPlanetRepo pr = new PlanetRepo();
            DetailsViewModel dvm = new DetailsViewModel();

            var planets = pr.GetByStarSystemId(id).ToList();
            var starSystem = ssr.GetById(id);
            dvm.StarSystem = starSystem;
            dvm.Planets = planets;
            var user = User.Identity;
            if (starSystem.Uploader == user.Name)
            {
                return View("Edit", starSystem);
            }
            return View("Details", dvm);
        }
Exemplo n.º 9
0
 // GET: StarSystem
 public ActionResult Index()
 {
     IStarSystemRepo ssr = new StarSystemRepo();
     var starSystems = ssr.GetAll().ToList();
     return View(starSystems);
 }