public int SetWebinarUserDetails(WebinarDashboardModel objWebinarDashboardModel) { logMessage = new StringBuilder(); try { logMessage.AppendLine(string.Format(CultureInfo.InvariantCulture, "Called {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name)); objDecisionPointEngine = new DecisionPointEngine(); objWebinarUsersResponse = new WebinarUsersResponse() { Id = objWebinarDashboardModel.Id, UserName = objWebinarDashboardModel.UserName, Password = objWebinarDashboardModel.Password, AppKey = objWebinarDashboardModel.AppKey, OrganiserId = objWebinarDashboardModel.OrganiserId, UserId = objWebinarDashboardModel.UserId, IsActive = objWebinarDashboardModel.IsActive, CreatedBy = Convert.ToInt32(Session["UserId"], CultureInfo.InvariantCulture), }; return(objDecisionPointEngine.setWebinarUserDetails(objWebinarUsersResponse)); } catch (Exception ex) { log.ErrorFormat("Error : {0}\n By : {1}-{2}", ex.ToString(), typeof(LoginController).Name, MethodBase.GetCurrentMethod().Name); return(0); } finally { logMessage.AppendLine(string.Format(CultureInfo.InvariantCulture, "End {0} function.", MethodBase.GetCurrentMethod().Name)); log.Info(logMessage.ToString()); } }
public ActionResult WebinarLogin(WebinarModel webinarModel) { // first we need to create the uri for the web request string uri = String.Format("https://api.citrixonline.com/oauth/access_token?grant_type=password&user_id={0}&password={1}&client_id={2}", webinarModel.emailId, webinarModel.password, webinarModel.apiKey); // then the request to login is created and sent. From the response // we need to store at least the access token and the organizer key // to use for further calls HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri); request.Accept = "application/json"; request.ContentType = "application/json"; string Result = string.Empty; try { var response = request.GetResponse(); //the following lines duplicate the response stream so we can read it for //deserialization and also re-read it and write it out. using (MemoryStream ms = new MemoryStream()) { var stream = response.GetResponseStream(); stream.CopyTo(ms); ms.Position = 0; stream.Close(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ResponseDirectLogin)); var deserialized = (ResponseDirectLogin)ser.ReadObject(ms); OauthToken = deserialized.AccessToken; OrganizerKey = deserialized.OrganizerKey; ms.Position = 0; using (var sr = new StreamReader(ms)) Result = sr.ReadToEnd(); } if (string.IsNullOrEmpty(webinarModel.OrganiserId)) { objWebinarUsersResponse = new WebinarUsersResponse() { Id = webinarModel.Id, UserName = webinarModel.emailId, Password = webinarModel.password, AppKey = webinarModel.apiKey, OrganiserId = OrganizerKey, UserId = webinarModel.UserId, IsActive = true, }; objDecisionPointEngine = new DecisionPointEngine(); objDecisionPointEngine.setWebinarUserDetails(objWebinarUsersResponse); } } catch (WebException e) { using (var sr = new StreamReader(e.Response.GetResponseStream())) Result = sr.ReadToEnd(); return(RedirectToAction("Error", "Login", new { errorMsg = Result })); } return(RedirectToAction("WebinarDashboard")); }