public GearPiece AddObject(string body, string name, string img, string faction) { var gearpiece = new GearPiece() { Id = Guid.NewGuid().ToString(), Name = name, ImageName = img, BodyPart = (BodyParts)Int32.Parse(body), Faction = String.IsNullOrEmpty(faction) ? Factions.Any : (Factions)Int32.Parse(faction) }; return OutfitProvider.AddGearPiece(gearpiece); }
public static GearPiece AddGearPiece(GearPiece piece) { string newList = ""; using (StreamReader reader = File.OpenText(dataPath)) { JsonSerializer serializer = new JsonSerializer(); IList<GearPiece> pieces = (IList<GearPiece>)serializer.Deserialize(reader, typeof(IList<GearPiece>)); if (pieces == null) pieces = new List<GearPiece>(); pieces.Add(piece); newList = JsonConvert.SerializeObject(pieces, Formatting.Indented); } File.WriteAllText(dataPath, newList); return piece; }