예제 #1
0
        public JsonResult Create(FormCollection collection, int id, int definitionId, bool isAntiExample)
        {
            var ajaxResponse = new Dictionary<string, string>();

            string body = collection["Example"];
            var example = new Example
            {
                Value = body,
                IsAntiExample = isAntiExample,
                DefinitionID = definitionId
            };

            try
            {
                CheckExampleBody(body);
                CheckExamlpe(example);
            }
            catch (ExampleAjaxException ex)
            {
                ajaxResponse["success"] = "false";
                ajaxResponse["message"] = ex.Message;
                return Json(ajaxResponse);
            }

            _db.Examples.AddObject(example);
            _db.SaveChanges();

            ajaxResponse["message"] = ExampleAjaxMessages.CREATE_COMPLETE;
            ajaxResponse["actionType"] = "create";
            ajaxResponse["success"] = "true";
            ajaxResponse["exampleID"] = example.ID.ToString(CultureInfo.InvariantCulture);
            ajaxResponse["body"] = body;
            ajaxResponse["isAntiExample"] = (isAntiExample) ? "true" : "false";

            return Json(ajaxResponse);
        }
예제 #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Examples EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToExamples(Example example)
 {
     base.AddObject("Examples", example);
 }
예제 #3
0
 /// <summary>
 /// Create a new Example object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="value">Initial value of the Value property.</param>
 /// <param name="isAntiExample">Initial value of the IsAntiExample property.</param>
 /// <param name="definitionID">Initial value of the DefinitionID property.</param>
 public static Example CreateExample(global::System.Int32 id, global::System.String value, global::System.Boolean isAntiExample, global::System.Int32 definitionID)
 {
     Example example = new Example();
     example.ID = id;
     example.Value = value;
     example.IsAntiExample = isAntiExample;
     example.DefinitionID = definitionID;
     return example;
 }
예제 #4
0
 /// <summary>
 /// Check if example is not null
 /// </summary>
 /// <param name="example"></param>
 private void CheckExamlpe(Example example)
 {
     if (example == null)
         throw new ExampleAjaxException(ExampleAjaxMessages.NULL_EXAMPLE);
 }