public bool PostSAQuestion(SAQuestionDAO sAQuestion) { SAQuestionServiceClient client = new SAQuestionServiceClient(); try { bool result = client.CreateSAQuestion(sAQuestion); return result; } catch (FaultException<KaskServiceException> e) { throw new HttpException(e.Message); } }
public ActionResult Create(FormCollection collection) { try { if (!string.IsNullOrEmpty(Request.Form["SAQuestionDescription"])) { // save application form data back to database through service using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri("http://localhost:51309"); httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage result = new HttpResponseMessage(); string resultContent = ""; // gather SAQuestionOpening form data SAQuestionDAO sAQuestion = new SAQuestionDAO(); sAQuestion.SAQuestionDescription = Request.Form["SAQuestionDescription"]; // post (save) SAQuestionOpening data result = httpClient.PostAsJsonAsync(ServiceURIs.ServiceSAQuestionUri, sAQuestion).Result; resultContent = result.Content.ReadAsStringAsync().Result; } return RedirectToAction("Index", "SAQuestions"); } else { // TODO: validation later on... return RedirectToAction("Create"); } } catch { // TODO: validation later on... return RedirectToAction("Create"); } }