Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. ------MODEL artigo.cs
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6.  
  7. namespace FirstREST.Lib_Primavera.Model
  8. {
  9. public class Artigo
  10. {
  11.  
  12. public string CodArtigo
  13. {
  14. get;
  15. set;
  16. }
  17.  
  18. public string NomeArtigo
  19. {
  20. get;
  21. set;
  22. }
  23.  
  24.  
  25. public float Desconto
  26. {
  27. get;
  28. set;
  29. }
  30.  
  31. public double Preco
  32. {
  33. get;
  34. set;
  35. }
  36.  
  37. public string Familia
  38. {
  39. get;
  40. set;
  41. }
  42.  
  43. public List<Model.Stock> StockExistente
  44. {
  45. get;
  46. set;
  47. }
  48.  
  49. }
  50. }
  51.  
  52. ------CONTROLLERS artigoController.cs
  53. using System;
  54. using System.Collections.Generic;
  55. using System.Linq;
  56. using System.Web;
  57. using System.Web.Mvc;
  58. using System.Net;
  59. using System.Net.Http;
  60. using System.Web.Http;
  61. using FirstREST.Lib_Primavera.Model;
  62.  
  63.  
  64. namespace FirstREST.Controllers
  65. {
  66. public class ArtigosController : ApiController
  67. {
  68. //
  69. // GET: /Artigos/
  70.  
  71. public IEnumerable<Lib_Primavera.Model.Artigo> GetArtigos()
  72. {
  73. return Lib_Primavera.PriIntegration.ListaArtigos();
  74. }
  75.  
  76.  
  77. // GET api/artigos/{id_artigo}
  78. public Artigo GetById(string id)
  79. {
  80. Lib_Primavera.Model.Artigo artigo = Lib_Primavera.PriIntegration.GetArtigo(id);
  81. if (artigo == null)
  82. {
  83. throw new HttpResponseException(
  84. Request.CreateResponse(HttpStatusCode.NotFound));
  85. }
  86. else
  87. {
  88. return artigo;
  89. }
  90. }
  91.  
  92.  
  93. public BestSellers GetBestSellers()
  94. {
  95. return Lib_Primavera.PriIntegration.ListaBestSellers();
  96. }
  97.  
  98. public IEnumerable<Lib_Primavera.Model.Artigo> GetMelhoresDescontos()
  99. {
  100. return Lib_Primavera.PriIntegration.ListaMelhoresDescontos();
  101. }
  102.  
  103. }
  104. }
  105.  
  106. ----- priIntegration.cs função ListaArtigos()
  107. public static List<Model.Artigo> ListaArtigos()
  108. {
  109.  
  110. StdBELista objList;
  111.  
  112. Model.Artigo art = new Model.Artigo();
  113. List<Model.Artigo> listArts = new List<Model.Artigo>();
  114.  
  115. if (PriEngine.InitializeCompany(FirstREST.Properties.Settings.Default.Company.Trim(), FirstREST.Properties.Settings.Default.User.Trim(), FirstREST.Properties.Settings.Default.Password.Trim()) == true)
  116. {
  117.  
  118. objList = PriEngine.Engine.Comercial.Artigos.LstArtigos();
  119.  
  120. while (!objList.NoFim())
  121. {
  122. art = new Model.Artigo();
  123. art.CodArtigo = objList.Valor("artigo");
  124. art.NomeArtigo = objList.Valor("descricao");
  125.  
  126.  
  127. listArts.Add(art);
  128. objList.Seguinte();
  129. }
  130.  
  131. return listArts;
  132.  
  133. }
  134. else
  135. {
  136. return null;
  137.  
  138. }
  139.  
  140. }
  141.  
  142.  
  143. ------ WebAPIConfig.cs dentro de AppStart
  144. //ArtigosController
  145.  
  146. config.Routes.MapHttpRoute(
  147. name: "getArtigos",
  148. routeTemplate: "api/artigos",
  149. defaults: new {controller="Artigos", action = "GetArtigos"}
  150. );
  151.  
  152. config.Routes.MapHttpRoute(
  153. name: "getBestsellers",
  154. routeTemplate: "api/artigos/bestsellers",
  155. defaults: new { controller = "Artigos", action = "GetBestSellers"}
  156. );
  157.  
  158. config.Routes.MapHttpRoute(
  159. name: "getDescontos",
  160. routeTemplate: "api/artigos/topdescontos",
  161. defaults: new { controller = "Artigos", action= "GetMelhoresDescontos" }
  162. );
  163.  
  164. config.Routes.MapHttpRoute(
  165. name: "getArtigo",
  166. routeTemplate: "api/artigos/{id}",
  167. defaults: new { controller = "Artigos"}
  168. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement