public HttpResponseMessage add(OptionType post, Int32 languageId = 0) { // Check for errors if (post == null) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null")); } else if (Language.MasterPostExists(languageId) == false) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The language does not exist")); } // Make sure that the data is valid post.title = AnnytabDataValidation.TruncateString(post.title, 100); post.google_name = AnnytabDataValidation.TruncateString(post.google_name, 50); // Add the post Int64 insertId = OptionType.AddMasterPost(post); post.id = Convert.ToInt32(insertId); OptionType.AddLanguagePost(post, languageId); // Return the success response return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been added")); } // End of the add method
} // End of the delete method #endregion #region Helper methods /// <summary> /// Add the option to the database /// </summary> /// <param name="optionType">A reference to a option type</param> /// <param name="options">A list of options</param> /// <param name="languageId">A language id</param> private void AddOption(OptionType optionType, List <Option> options, Int32 languageId) { // Save the option type long insertId = OptionType.AddMasterPost(optionType); optionType.id = Convert.ToInt32(insertId); OptionType.AddLanguagePost(optionType, languageId); // Save all the options foreach (Option option in options) { option.option_type_id = optionType.id; insertId = Option.AddMasterPost(option); option.id = Convert.ToInt32(insertId); Option.AddLanguagePost(option, languageId); } } // End of the AddOption method