public IActionResult AddPlanet(IFormFile Photo, string Name, string Galaxy, uint Radius, uint Temperature, DateTime Date, string St, uint Dist, string Unit, bool atm, bool type) { byte[] ph = new byte[0]; if (Photo != null) { var str = Photo.OpenReadStream(); ph = new byte[str.Length]; str.Read(ph, 0, ph.Length); str.Close(); } var xml = new XmlSerializer(typeof(List <DBPlanet>)); var stream = new MemoryStream(HttpContext.Session.Get("planets")); var planets = xml.Deserialize(stream) as List <DBPlanet>; var planet = new DBPlanet(Date, ph, Name, new Distance(Dist, StringToUnit(Unit)), Radius, atm, type?PlanetType.Tought : PlanetType.Gas, "", Galaxy, Temperature) { Star = St }; var mx = new XmlSerializer(typeof(List <DBMoon>)); var st = new MemoryStream(HttpContext.Session.Get("moons")); var moons = mx.Deserialize(st) as List <DBMoon>; planet.Moons = new Collection <DBMoon>(moons); planets.Add(planet); SaveToSession(planets, xml); HttpContext.Session.Set("img", ph); HttpContext.Session.Set("imgflag", new byte[1] { 1 }); //HttpContext.Response.WriteAsync(@"onload = ""window.close();"""); //planet.Id = -1; return(View("~/Views/Views/PlanetView.cshtml", planet)); }
public IActionResult ChangePlanet(IFormFile Photo, string Name, string Galaxy, uint Radius, uint Temperature, DateTime Date, string St, uint Dist, string Unit, bool atm, bool type, int id, int StarId) { byte[] ph = new byte[0]; if (Photo != null) { var str = Photo.OpenReadStream(); ph = new byte[str.Length]; str.Read(ph, 0, ph.Length); str.Close(); } var planet = new DBPlanet(Date, ph, Name, new Distance(Dist, StringToUnit(Unit)), Radius, atm, type ? PlanetType.Tought : PlanetType.Gas, "", Galaxy, Temperature) { Star = St, Id = id, StarId = StarId }; //########################################################################################## var mx = new XmlSerializer(typeof(List <DBMoon>)); var st = new MemoryStream(HttpContext.Session.Get("moons")); var moons = mx.Deserialize(st) as List <DBMoon>; db.Moons.AddRange(moons); foreach (var moon in moons) { planet.Moons.Add(moon);// = new Collection<DBMoon>(moons); } //########################################################################################## HttpContext.Session.Set("img", ph); HttpContext.Session.Set("imgflag", new byte[1] { 1 }); db.Entry(planet).State = EntityState.Modified; db.SaveChanges(); return(View("~/Views/Views/PlanetView.cshtml", planet)); }
private static void PrintPlanets(DBStar star, ISheet sheet, int i, IRow row, int j, ICell cell, DBPlanet planet) { row = sheet.GetRow(i); cell = row.GetCell(j); cell.SetCellValue(planet.Name); cell = row.GetCell(j + 1) ?? row.CreateCell(j + 1); cell.SetCellValue(planet.MiddleDistanceValue + planet.MiddleDistanceUnit.ToString()); cell = row.GetCell(j + 2) ?? row.CreateCell(j + 2); cell.SetCellValue(planet.Radius); cell = row.GetCell(j + 3) ?? row.CreateCell(j + 3); cell.SetCellValue(planet.Star); cell = row.GetCell(j + 4) ?? row.CreateCell(j + 4); cell.SetCellValue(planet.Temperature); cell = row.GetCell(j + 5) ?? row.CreateCell(j + 5); cell.SetCellValue(planet.Type.ToString()); cell = row.GetCell(j + 6) ?? row.CreateCell(j + 6); cell.SetCellValue(planet.InventingDate); cell.CellStyle.DataFormat = 14; cell = row.GetCell(j + 7) ?? row.CreateCell(j + 7); cell.SetCellValue(planet.HasAtmosphere); if (planet != star.Planets.Last()) { row = sheet.CopyRow(i, i + 1); } }