public System.Web.Mvc.JsonResult GetConsumed(string userID, int id) { var smoke = consumes.GetById(id); var json = new System.Web.Mvc.JsonResult(); json.Data = new { smoke }; return(json); }
public System.Web.Mvc.JsonResult Consumeds(string userID) { var consumed = consumes.GetByUserId(userID); var json = new System.Web.Mvc.JsonResult(); json.Data = new { consumed }; return(json); }
private string ToJSONString(string ConvertStringToJSON) { string ConvertedToJSONString = ""; System.Web.Mvc.JsonResult json = new System.Web.Mvc.JsonResult { Data = ConvertStringToJSON }; ConvertedToJSONString = new JavaScriptSerializer().Serialize(json.Data); return(ConvertedToJSONString); }
public string TestJSON() { /*PaymentTransactionManager paymentTransactionManager = new PaymentTransactionManager(); * paymentTransactionManager.MockPurchaseRequest(); */ System.Web.Mvc.JsonResult json = new System.Web.Mvc.JsonResult { Data = "This is a JSON test response." }; string son = new JavaScriptSerializer().Serialize(json.Data); return(son); }
public System.Web.Mvc.ActionResult GetCustomerById(int id) { var inputId = id; SalesService.Models.Customer custmerById; using (var salesDBEntities = new SalesDBEntities()) { var customerFromDatabase = salesDBEntities.Customers.Where(item => item.CustomerID == id).ToList().First(); custmerById = new Models.Customer() { FirstName = customerFromDatabase.FirstName, CustomerID = customerFromDatabase.CustomerID, LastName = customerFromDatabase.LastName, MiddleInitial = customerFromDatabase.MiddleInitial }; } var result = new System.Web.Mvc.JsonResult(); result.Data = custmerById; return(result); }
public System.Web.Mvc.JsonResult GetJsonResult() { //if (DisplayMessage) //{ // if (string.IsNullOrWhiteSpace(MessageTitle)) // { // switch (State) // { // case Enums.JsonResultStates.Error: // { // MessageTitle = Resources.Captions.ErrorState; // break; // } // case Enums.JsonResultStates.Success: // { // MessageTitle = Resources.Captions.SuccessState; // break; // } // case Enums.JsonResultStates.Warning: // { // MessageTitle = Resources.Captions.WarningState; // break; // } // } // } //} System.Web.Mvc.JsonResult jsonResult = new System.Web.Mvc.JsonResult { Data = this, RecursionLimit = null, MaxJsonLength = int.MaxValue, ContentEncoding = System.Text.Encoding.UTF8, JsonRequestBehavior = System.Web.Mvc.JsonRequestBehavior.AllowGet }; return(jsonResult); }
public System.Web.Mvc.ActionResult GetCustomerByName(string name) { SalesService.Models.Customer custmerByName; using (var salesDBEntities = new SalesDBEntities()) { var customerFromDatabase = salesDBEntities.Customers.FirstOrDefault(item => item.FirstName.Contains(name) || item.LastName.Contains(name)); if (customerFromDatabase == null) { } custmerByName = new Models.Customer() { FirstName = customerFromDatabase.FirstName, CustomerID = customerFromDatabase.CustomerID, LastName = customerFromDatabase.LastName, MiddleInitial = customerFromDatabase.MiddleInitial }; } var result = new System.Web.Mvc.JsonResult(); result.Data = custmerByName; return(result); }
public string GetItemsInGamesByMember(FormDataCollection formData) { if (formData != null) { string memberIDString = formData.Get("MemberID"); string returnLimitString = formData.Get("ReturnLimit"); int MemberID = Convert.ToInt32(memberIDString); int ReturnLimit = Convert.ToInt32(returnLimitString); if (MemberID > 0 && ReturnLimit > 0) { IQueryable <MemberInGame> memberInGames = db.MemberInGames.Include("Game.ProductInGames.Product.Imagedetails").Include("Game.GameType").Include("Game.GameRules").Where(x => x.MemberID == MemberID).Take(ReturnLimit); List <MemberInGameItem> memberInGameItems = new List <MemberInGameItem>(); foreach (MemberInGame memberInGame in memberInGames) { MemberInGameItem memberInGameItem = new MemberInGameItem(); // This should happen in the constructor of MemberInGameItem. memberInGameItem.GameDateTime = DateTime.MinValue; memberInGameItem.DateTimeInserted = DateTime.MinValue; memberInGameItem.DateTimeUpdated = DateTime.MinValue; Game game = memberInGame.Game; // Set Game properties memberInGameItem.GameID = game.GameID; memberInGameItem.GameCode = game.GameCode; memberInGameItem.GameDescription = game.GameDescription; memberInGameItem.GameName = game.GameName; memberInGameItem.GameTypeName = game.GameType.GameTypeName; //memberInGameItem.GameDateTime = ; comes from game rules where state = ? //memberInGameItem.GamePrice = ; //memberInGameItem.GameStatus = ; //memberInGameItem.GameStatusColor = ; // set product properties - this needs to be a collection in the MemberInGameItem class, it's not a 1:1 relationship, 1 game can have * products. // I'm only taking the first one at this point. foreach (ProductInGame productInGame in game.ProductInGames) { Product product = productInGame.Product; memberInGameItem.ProductID = product.ProductID; memberInGameItem.ProductName = product.ProductName; memberInGameItem.ProductDescription = product.ProductDescription; memberInGameItem.ProductPrice = (product.ProductPrice != null) ? (decimal)product.ProductPrice : 0; memberInGameItem.OwnerID = product.OwnerID; // loop through product categories.... because one product can live in multiple categories!!! // I'm only taking the first one at this point. foreach (ProductInCategory productInCategory in product.ProductInCategories) { ProductCategory productCategory = productInCategory.ProductCategory; memberInGameItem.ProductCategory = productCategory.ProductCategoryName; break; } //Quick hack to get the 1st image Imagedetail image = db.Imagedetails.Where(x => x.ProductId == product.ProductID).First(); memberInGameItem.ProductImage = image.ImageID.ToString(); break; } memberInGameItems.Add(memberInGameItem); } // string returnJSONResult = ""; /*using (MemoryStream memoryStream = new MemoryStream()) * { * DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MemberInGameItem)); * dataContractJsonSerializer.WriteObject(memoryStream, memberInGameItems); * * memoryStream.Position = 0; * var sr = new StreamReader(memoryStream); * returnJSONResult = sr.ReadToEnd(); * } * return returnJSONResult; */ System.Web.Mvc.JsonResult json = new System.Web.Mvc.JsonResult { Data = memberInGameItems }; string son = new JavaScriptSerializer().Serialize(json.Data); return(son); } } return(""); }
public string Test([FromBody] Users model) { System.Web.Mvc.JsonResult jsonresult = new System.Web.Mvc.JsonResult(); jsonresult.Data = new { msg = model.Name }; return(jsonresult.Data.ToString()); }
public override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext) { string publicKey = string.Empty; try { publicKey = filterContext.RequestContext.HttpContext.Request.Headers.Get("PublicKey").Trim(); } catch { var json = new System.Web.Mvc.JsonResult(); json.ContentType = "text/HTML"; json.Data = new TokenStatus { Code = "3000", Message = "缺失PublicKey参数" }; json.JsonRequestBehavior = System.Web.Mvc.JsonRequestBehavior.AllowGet; filterContext.Result = json; return; } string privateKey = string.Empty; try { privateKey = filterContext.RequestContext.HttpContext.Request.Headers.Get("PrivateSecret"); } catch { var json = new System.Web.Mvc.JsonResult(); json.ContentType = "text/HTML"; json.Data = new TokenStatus { Code = "5000", Message = "缺失PrivateKey参数" }; json.JsonRequestBehavior = System.Web.Mvc.JsonRequestBehavior.AllowGet; filterContext.Result = json; return; } long timeStamp = 0; try { timeStamp = long.Parse(filterContext.RequestContext.HttpContext.Request.Headers.Get("TimeStamp")); } catch { var json = new System.Web.Mvc.JsonResult(); json.ContentType = "text/HTML"; json.Data = new TokenStatus { Code = "0000", Message = "缺少TimeStamp参数" }; json.JsonRequestBehavior = System.Web.Mvc.JsonRequestBehavior.AllowGet; filterContext.Result = json; return; } var error = DateTime.Now.Ticks - timeStamp; if (Math.Abs(error) > 180000) { var json = new System.Web.Mvc.JsonResult(); json.ContentType = "text/HTML"; json.Data = new TokenStatus { Code = "1000", Message = "时间戳不在合理范围内,请检测您服务器的当前时间" }; json.JsonRequestBehavior = System.Web.Mvc.JsonRequestBehavior.AllowGet; filterContext.Result = json; return; } Token token; using (TokenDbContext content = new TokenDbContext()) { token = content.Set<Token>().SingleOrDefault(t => t.OpenToken.ToUpper() == publicKey.ToUpper()); if (token == null) { var json = new System.Web.Mvc.JsonResult(); json.ContentType = "text/HTML"; json.Data = new TokenStatus { Code = "2000", Message = "公钥不存在" }; json.JsonRequestBehavior = System.Web.Mvc.JsonRequestBehavior.AllowGet; filterContext.Result = json; return; } string resoler = token.OpenToken + token.SecretToken + timeStamp; string localSecret = MD5Encoding(resoler); if (privateKey.Trim().ToUpper() != localSecret.ToUpper()) { var json = new System.Web.Mvc.JsonResult(); json.ContentType = "text/HTML"; json.Data = new TokenStatus { Code = "4000", Message = "提供的参数有误" }; json.JsonRequestBehavior = System.Web.Mvc.JsonRequestBehavior.AllowGet; filterContext.Result = json; return; } } base.OnActionExecuting(filterContext); }
/// <summary> /// Cria a instancia com base no resultado informado. /// </summary> /// <param name="jsonResult"></param> public JsonOperationResult(System.Web.Mvc.JsonResult jsonResult) { jsonResult.Require("jsonResult").NotNull(); _innerResult = jsonResult; }
/// <summary> /// Construtor padrão. /// </summary> public JsonOperationResult() { _innerResult = new System.Web.Mvc.JsonResult(); }