public static Object solidifyDatabaseObjects(Object lazyProperties) { try { // Double check list is not empty if (lazyProperties == null) { return null; } // Remove the Lazy Objects appended to the List and solidify Object with necessary data if (lazyProperties is List<fun_IsUserInSystem_Result>) { // Cast object to its proper type List<fun_IsUserInSystem_Result> userProperties = (List<fun_IsUserInSystem_Result>)lazyProperties; // Reshape LazyObject UserSerializable potentialUser = new UserSerializable( userProperties.FirstOrDefault().userId , userProperties.FirstOrDefault().lastName , userProperties.FirstOrDefault().firstName , userProperties.FirstOrDefault().email , userProperties.FirstOrDefault().gender , userProperties.FirstOrDefault().typeOfUser , userProperties.FirstOrDefault().userPicAddress ); return potentialUser; } else if (lazyProperties is List<fun_GetOrRetriveAllCoursesFromUser_Result>) { // Cast object to its proper type List<fun_GetOrRetriveAllCoursesFromUser_Result> userCourseProperties = (List<fun_GetOrRetriveAllCoursesFromUser_Result>)lazyProperties; // Make new list to get all Courses into List<CoursesSerializable> userCoursesList = new List<CoursesSerializable>(); // Remove the Lazy Objects appended to the List and solidify Object with necessary data foreach (var course in userCourseProperties) { userCoursesList.Add(new CoursesSerializable(course.courseName, course.courseCode)); } return userCoursesList; } else if (lazyProperties is List<fun_GetOrRetriveUserDocuments_Result>) { // Cast List<fun_GetOrRetriveUserDocuments_Result> userEventsProperties = (List<fun_GetOrRetriveUserDocuments_Result>)lazyProperties; // Remove Lazy by building object // Make new list to get all Events from user into List<EventsSerializable> userEventsList = new List<EventsSerializable>(); // Remove the Lazy Objects appended to the List and solidify Object with necessary data foreach (var userEvent in userEventsProperties) { userEventsList.Add(new EventsSerializable( userEvent.docText , userEvent.docDesc , Convert.ToString(userEvent.docDate) )); } return userEventsList; } else if (lazyProperties is List<fun_GetAllChatUsers_Result>) { // Cast object to its proper type List<fun_GetAllChatUsers_Result> chatUsersProperties = (List<fun_GetAllChatUsers_Result>)lazyProperties; // Make new list to get all Events from user into List<UserSerializable> userChatList = new List<UserSerializable>(); foreach (var chatUser in chatUsersProperties) { // Reshape LazyObject userChatList.Add( new UserSerializable( chatUser.userId , chatUser.lastName , chatUser.firstName , chatUser.email , chatUser.gender , chatUser.typeOfUser , chatUser.userPicAddress )); } return userChatList; } return null; } catch (Exception ex) { String debug = ex.ToString(); String de = debug; return null; } }
public static Object solidifyDatabaseObjects(Object lazyProperties) { try { // Double check list is not empty if (lazyProperties == null) { return(null); } // Remove the Lazy Objects appended to the List and solidify Object with necessary data if (lazyProperties is List <fun_IsUserInSystem_Result> ) { // Cast object to its proper type List <fun_IsUserInSystem_Result> userProperties = (List <fun_IsUserInSystem_Result>)lazyProperties; // Reshape LazyObject UserSerializable potentialUser = new UserSerializable( userProperties.FirstOrDefault().userId , userProperties.FirstOrDefault().lastName , userProperties.FirstOrDefault().firstName , userProperties.FirstOrDefault().email , userProperties.FirstOrDefault().gender , userProperties.FirstOrDefault().typeOfUser , userProperties.FirstOrDefault().userPicAddress ); return(potentialUser); } else if (lazyProperties is List <fun_GetOrRetriveAllCoursesFromUser_Result> ) { // Cast object to its proper type List <fun_GetOrRetriveAllCoursesFromUser_Result> userCourseProperties = (List <fun_GetOrRetriveAllCoursesFromUser_Result>)lazyProperties; // Make new list to get all Courses into List <CoursesSerializable> userCoursesList = new List <CoursesSerializable>(); // Remove the Lazy Objects appended to the List and solidify Object with necessary data foreach (var course in userCourseProperties) { userCoursesList.Add(new CoursesSerializable(course.courseName, course.courseCode)); } return(userCoursesList); } else if (lazyProperties is List <fun_GetOrRetriveUserDocuments_Result> ) { // Cast List <fun_GetOrRetriveUserDocuments_Result> userEventsProperties = (List <fun_GetOrRetriveUserDocuments_Result>)lazyProperties; // Remove Lazy by building object // Make new list to get all Events from user into List <EventsSerializable> userEventsList = new List <EventsSerializable>(); // Remove the Lazy Objects appended to the List and solidify Object with necessary data foreach (var userEvent in userEventsProperties) { userEventsList.Add(new EventsSerializable( userEvent.docText , userEvent.docDesc , Convert.ToString(userEvent.docDate) )); } return(userEventsList); } else if (lazyProperties is List <fun_GetAllChatUsers_Result> ) { // Cast object to its proper type List <fun_GetAllChatUsers_Result> chatUsersProperties = (List <fun_GetAllChatUsers_Result>)lazyProperties; // Make new list to get all Events from user into List <UserSerializable> userChatList = new List <UserSerializable>(); foreach (var chatUser in chatUsersProperties) { // Reshape LazyObject userChatList.Add(new UserSerializable( chatUser.userId , chatUser.lastName , chatUser.firstName , chatUser.email , chatUser.gender , chatUser.typeOfUser , chatUser.userPicAddress )); } return(userChatList); } return(null); } catch (Exception ex) { String debug = ex.ToString(); String de = debug; return(null); } }
public void systemHandler(Dictionary<String, Object> data) { // Retrive context from dictionary HttpContext context = (HttpContext)data["HttpResponse"]; // Set type of expected string context.Response.ContentType = "text/html;charset=UTF-8"; // Initialize Values String username = ""; String password = ""; // Get parameters from url username = context.Request.Params["username"]; password = context.Request.Params["password"]; Dictionary<String, Object> portalData = null; // Send values to be evaluated try { // Double check just in the very remote case the front end did not handle well the input for these fields // before sending it remotely accross the web to see if it exists if (username == "undefined" || password == "undefined" || username == null || password == null || username == "" || password == "") { // So if the username field or password is missing when they first log in we will redirect and terminate // the execution of the code until the fields are completed properly // Since I am using the $locationProvider on the front end I don't need to specify the root since it will handle // all for me otherwise when it makes a 404 no found it will return the whole index html page context.Response.Redirect("", false); context.ApplicationInstance.CompleteRequest(); return; } // Communicate to remote function to get all info about person trying to log-in // Outside of classed is mapped to this -> private UserFacadeRemote personFacade; // In java the framework will handle the instantiation and removal of objects but // since I don't how to set it up in asp.net I had to do it this way // Instance of userFacade userFacade = new UserFacade(); // Execute Remote function call to evaluate the username and password portalData = userFacade.login(username, password); // Evaluate if there is a user with that usename and password if (portalData == null) { // Redirect with error, tipically its documented to use true // for the second parameter but that causes to through an exceptio // which is aborting thread which does the trick but its definetely // poor login so I use false which does the redirect but won't terminate the execution of the code // the following line will terminate the request and I use return to not allow any further code to be executed // Since I am using the $locationProvider on the front end I don't need to specify the root since it will handle // all for me otherwise when it makes a 404 no found it will return the whole index html page context.Response.Redirect("", false); context.ApplicationInstance.CompleteRequest(); return; } // Up to this point user should exist so lets Store User Locally // By retriving the user profile if (portalData.ContainsKey("UserProfile")){ userLogged = (UserSerializable)portalData["UserProfile"]; } else { // Redirect with error context.Response.Redirect("", false); context.ApplicationInstance.CompleteRequest(); return; } // and saving authentication token on session context.Session["userId"] = userLogged.getPersonId(); context.Session["userFistName"] = userLogged.getFirstName(); context.Session["userLastName"] = userLogged.getLastName(); // Return Serialized object to Http Request back in AngularJS //JavaScriptSerializer js = new JavaScriptSerializer(); //String testJSSerializer = js.Serialize(portalData); String testSerialization = JsonConvert.SerializeObject(portalData); // Send Object Serialized context.Response.Write(JsonConvert.SerializeObject(portalData)); } catch (Exception ex) { String debug = ex.ToString(); String de = debug; } }