public ActionResult EditSector(SectorForm form) { Debug.WriteLine($"POST: Star Map Controller: Edit Sector"); var game = GameState.Game; DB_sectors dbSector = game.Sector.Info; dbSector.name = form.Name; dbSector.description = form.Description; dbSector.gmnotes = form.GMNotes; Database.Session.Update(dbSector); Database.Session.Flush(); return(RedirectToRoute("StarMap")); }
public ActionResult NewSector(SectorForm form) { Debug.WriteLine($"POST: Star Map Controller: New Sector"); if (form.FileUpload == null || form.FileUpload.ContentLength == 0) { if (form.Width == 0) { ModelState.AddModelError("Width", "Width must be set to a value greater than 0"); } if (form.Height == 0) { ModelState.AddModelError("Height", "Height must be set to a value greater than 0"); } } else { if (form.FileUpload.ContentType != "text/plain") { ModelState.AddModelError("FileUpload", "Your file must be of format .txt"); } } if (!ModelState.IsValid) { return(View(form)); } var game = GameState.Game; Fotiv_Automator.Models.StarMapGenerator.Models.StarSector sector = null; if (form.FileUpload == null || form.FileUpload.ContentLength == 0) { Debug.WriteLine($"Star Map Controller: Generate Sector"); StarSectorGenerator generator = new StarSectorGenerator(form.Width, form.Height); sector = generator.Generate(); } else { Debug.WriteLine($"Star Map Controller: Load Sector From File"); List <string> linesOfText = new List <string>(); using (System.IO.StreamReader reader = new System.IO.StreamReader(form.FileUpload.InputStream)) { while (!reader.EndOfStream) { linesOfText.Add(reader.ReadLine()); } } sector = StarSectorGenerator.Load(linesOfText); } if (sector == null || sector.Sector.Count == 0) { Debug.WriteLine("Generation Failed: Sector Not Saved"); } else { DB_sectors dbSector = new DB_sectors(); dbSector.game_id = game.ID; dbSector.name = form.Name; dbSector.description = form.Description; dbSector.gmnotes = form.GMNotes; Database.Session.Save(dbSector); SaveSector(game, dbSector, sector); } Database.Session.Flush(); return(RedirectToRoute("game", new { gameID = game.ID })); }