/// <summary> /// Insert the encoded JSON into the database /// </summary> /// <param name="data"></param> /// <param name="side"></param> public static void InsertData(Data data, Side side, IWAESAssignmentDBEntities context) { var db = context; // Create the object to interact with the database using Entity Framework var existentData = db.Data.Find(data.Id); // Get the record based on the ID // Validate if the record exists, if so update it if (existentData != null) { switch (side) { case Side.Left: existentData.LeftSide = data.LeftSide; // Inserts the LEFT encoded Json into the record break; case Side.Right: existentData.RightSide = data.RightSide; // Inserts the Right encoded Json into the record break; } } else // If there is not any record with the same id searched before, create a new one { db.Data.Add(data); // Insert the new data into de databese } db.SaveChanges(); // Save the changes }
public DataController(IWAESAssignmentDBEntities context) { db = context; }