protected void Page_Load(object sender, EventArgs e) { bool isAuthenticated = false; List <ICardDetails> CardList = new List <ICardDetails>(); try { if (CookieProxy.Instance().HasKey("t")) { IUserProfile UserProfileObj = new UserProfile(); UserProfileObj.SetToken(CookieProxy.Instance().GetValue("t").ToString()); CRUDBusinessLayerTemplate <ICardDetails> CardObj = new CardDetailsBusinessLayerTemplate(UserProfileObj); CardList = CardObj.Select(); isAuthenticated = true; } else { isAuthenticated = false; } } catch (NullReferenceException) { isAuthenticated = false; CookieProxy.Instance().SetValue("LoginMessage", "For security reasons, please relogin", DateTime.Now.AddDays(2)); } catch (Exception) { isAuthenticated = false; CookieProxy.Instance().SetValue("LoginMessage", "An error occured, this event has been logged. Please try again later", DateTime.Now.AddDays(2)); } finally { var JSONResponse = new { isAuthenticated, CardList }; Response.Write(new JavaScriptSerializer().Serialize(JSONResponse)); } }
protected void Page_Load(object sender, EventArgs e) { APIResponse ResponseAPI = APIResponse.NOT_OK; try { if (CookieProxy.Instance().HasKey("t")) { IUserProfile UserProfileObj = new UserProfile(CookieProxy.Instance().GetValue("t").ToString()); ICardDetails CardObj = new CardDetails(int.Parse(Request.Form["cid"].ToString())); CRUDBusinessLayerTemplate <ICardDetails> CardCRUD = new CardDetailsBusinessLayerTemplate(UserProfileObj); ResponseAPI = CardCRUD.Delete(CardObj); } else { ResponseAPI = APIResponse.NOT_AUTHENTICATED; } } catch (NullReferenceException) { ResponseAPI = APIResponse.NOT_AUTHENTICATED; } catch (Exception) { ResponseAPI = APIResponse.NOT_OK; } finally { if (ResponseAPI == APIResponse.NOT_AUTHENTICATED) { CookieProxy.Instance().SetValue("LoginMessage", "For security reasons, please relogin".ToString(), DateTime.Now.AddDays(2)); } var ResponseObj = new { Response = ResponseAPI.ToString() }; Response.Write(new JavaScriptSerializer().Serialize(ResponseObj)); } }