private static Token CreateToken(CreateTokenViewModel model) { Token token; switch (model.TokenType) { case TokenType.Register: if (!model.TotalSupply.HasValue) { throw new ArgumentException("Total supply is required for token register"); } token = new TokenRegister { Supply = model.TotalSupply.Value }; break; case TokenType.Account: token = new TokenAccount(); break; default: throw new ArgumentOutOfRangeException(); } token.Name = model.Name; token.Identifier = model.Identifier; return(token); }
public JsonResult SetMemory(TokenAccount tk) { if (tk != null) { if (tk.Flag.Equals("cookie")) { Session.Abandon(); HttpCookie cookie = new HttpCookie("Accout"); cookie.HttpOnly = true; HttpContext.Response.Cookies.Remove("Accout"); cookie.Value = tk.AccoutToken; cookie.Expires = DateTime.Now.AddDays(2); HttpContext.Response.SetCookie(cookie); TokenAccount tokenAccount = new TokenAccount() { AccoutToken = Request.Cookies.Get("Accout").Value, Flag = "cookie" }; return(Json(tokenAccount)); } else if (tk.Flag.Equals("session")) { Response.Cookies["Accout"].Expires = DateTime.Now.AddDays(-1); Session["Accouts"] = tk.AccoutToken; TokenAccount tokenAccount = new TokenAccount() { AccoutToken = Session["Accouts"].ToString(), Flag = "sesstion" }; return(Json(tokenAccount)); } } return(Json(tk)); }