public ActionResult CreateUser(Models.NewUser param) { param.company = "Spectrum Management Authority, Jamaica"; param.clientId = 11698; if (Session["key"] != null) { param.access_key = Session["key"].ToString(); var client = new HttpClient(); client.BaseAddress = new Uri("http://server-erp2.sma.gov.jm:1786/api/user/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var content = new StringContent(JsonConvert.SerializeObject(param), Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync("RegisterCompanyUserV2", content).Result; if (response.IsSuccessStatusCode) { string result = response.Content.ReadAsStringAsync().Result; Models.UserDetails userDetails = JsonConvert.DeserializeObject <Models.UserDetails>(result); return(Json(new { userDetails, }, JsonRequestBehavior.AllowGet)); } else { string result = response.Content.ReadAsStringAsync().Result; return(Json(new { result, }, JsonRequestBehavior.AllowGet)); } } else { return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, "invalid session")); } }
public ActionResult Register(Models.NewUser user) { if (ModelState.IsValid) { if (user.IsDuplicate(user.UserName)) { ModelState.AddModelError("", "Username aleady exists."); } else { var result = CreateUser(user); if (result < 1) { ModelState.AddModelError("", "There was a problem creating your username."); } else { FormsAuthentication.SetAuthCookie(user.UserName, user.RememberMe); return(RedirectToAction("Index", "Home")); } } } return(View(user)); }