public ActionResult Create(ArticleViewModel model)
        {
            try
            {
                var response = _spellingService.CheckSpellingAsync(model).Result;

                if (!string.IsNullOrEmpty(response))
                {
                    model.SpellingResponse = response;
                    return(View(model).WithInfo("Info", "We have checked the spelling of this article"));
                }

                if (!ModelState.IsValid)
                {
                    return(View(model).WithWarning("Error", "Please correct the errors and try again"));
                }

                MockDataStoreHelper.Add(model);
            }
            catch (Exception)
            {
                return(View(model).WithWarning("Error", "Unable to save record"));
            }


            return(RedirectToAction("Index").WithSuccess("Completed", "Record Saved"));
        }
예제 #2
0
        public ActionResult Create(ArticleViewModel model)
        {
            try
            {
                string clientId = null;
                // get the client ID if it exists
                var clientIdCookie = Request.Cookies.Get("ClientId");
                clientId = clientIdCookie == null ? "" : clientIdCookie.Value;

                // check the article body for mistakes
                var spellingResponse = _spellingService.CheckSpellingAsync(model.Body, clientId).Result;
                Debug.WriteLine($"Client ID: {clientId} Trace ID: {spellingResponse.TraceId}");
                // set the clientId cookie
                if (spellingResponse.ClientId != null)
                {
                    Response.Cookies.Set(new HttpCookie("ClientId", spellingResponse.ClientId));
                }

                if (!string.IsNullOrEmpty(spellingResponse.Text))
                {
                    model.SpellingResponse = spellingResponse.Text;
                    return(View(model).WithInfo("Info", "We have checked the spelling of this article"));
                }

                if (!ModelState.IsValid)
                {
                    return(View(model).WithWarning("Error", "Please correct the errors and try again"));
                }

                MockDataStoreHelper.Add(model);
            }
            catch (Exception)
            {
                return(View(model).WithWarning("Error", "Unable to save record"));
            }


            return(RedirectToAction("Index").WithSuccess("Completed", "Record Saved"));
        }