public ObjetoData DataToObject(HttpContext context) { ObjetoData frontData = new ObjetoData(); string data = new StreamReader(context.Request.InputStream).ReadToEnd(); var dsrs = new JavaScriptSerializer(); Dictionary <string, string> values = dsrs.Deserialize <Dictionary <string, string> >(data); foreach (var item in values) { switch (item.Key) { case "TerritoryID": frontData.TerritoryID = item.Value; break; case "TerritoryDescription": frontData.TerritoryDescription = item.Value; break; case "RegionID": frontData.RegionID = int.Parse(item.Value); break; case "Method": frontData.Method = item.Value; break; } } return(frontData); }
public void AgregarUno(HttpContext context, ObjetoData data) { TerritoryLogic terriLogic = new TerritoryLogic(); Territories miTr = new Territories { RegionID = data.RegionID, TerritoryDescription = data.TerritoryDescription, TerritoryID = data.TerritoryID }; context.Response.Write(terriLogic.AgregarUno(miTr)); }
public void EliminarUno(HttpContext context, ObjetoData dataForDelete) { TerritoryLogic terriLogic = new TerritoryLogic(); Territories miTr = new Territories { RegionID = dataForDelete.RegionID, TerritoryDescription = dataForDelete.TerritoryDescription, TerritoryID = dataForDelete.TerritoryID }; context.Response.Write(terriLogic.EliminarTerritorio(miTr)); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; if (context.Request.HttpMethod == "POST") { ObjetoData misDatos = this.DataToObject(context); switch (misDatos.Method) { case "AgregarUno": this.AgregarUno(context, misDatos); break; case "ModificarUno": this.ModificarUno(context, misDatos); break; case "EliminarUno": this.EliminarUno(context, misDatos); break; } } else { switch (context.Request["Method"]) { case "TraerTodos": this.TraerTodos(context); break; case "TraerUno": this.TraerUno(context, context.Request["Data"]); break; } } }