Guest User

Untitled

a guest
Jul 5th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.47 KB | None | 0 0
  1. CREATE TABLE USER (
  2. ID BIGINT(20) NOT NULL AUTO_INCREMENT,
  3. USERNAME VARCHAR(50) NOT NULL,
  4. FIRSTNAME VARCHAR(50) NOT NULL,
  5. MIDDLEINITIALS VARCHAR(10) NULL,
  6. LASTNAME VARCHAR(50) NOT NULL,
  7. PASSWORD VARCHAR(64) NOT NULL,
  8. GENDER CHAR(1) NULL,
  9. ACTIVE CHAR(1) NOT NULL,
  10. CONSTRAINT USER_PK PRIMARY KEY (ID),
  11. CONSTRAINT USER_UK UNIQUE KEY (USERNAME)
  12. ) ENGINE=InnoDB;
  13.  
  14. SELECT * FROM User;
  15.  
  16. 1,'SYSTEM','SYSTEM',NULL,'ADMIN','senha123',NULL,'Y'
  17. 2,'JMICHEL','JEAN','J','MICHEL','senha123','M','Y'
  18.  
  19. using System;
  20. using System.Text;
  21. using System.ComponentModel.DataAnnotations;
  22. using System.ComponentModel.DataAnnotations.Schema;
  23.  
  24. namespace WEB_API_DOT_NET_CORE.Model
  25. {
  26. [Table("User")]
  27. public class UserModel
  28. {
  29.  
  30. private Int64 id;
  31. private String username;
  32. private String firstName;
  33. private String middleInitials;
  34. private String lastName;
  35. private String password;
  36. private char gender;
  37. private char active;
  38.  
  39. [Key]
  40. public Int64 Id {
  41. set { this.id = value; }
  42. get { return this.id; }
  43.  
  44. }
  45. [StringLength(50)]
  46. public String Username {
  47. set { this.username = value; }
  48. get { return this.username; }
  49. }
  50. [StringLength(50)]
  51. public String FirstName
  52. {
  53. set { this.firstName = value; }
  54. get { return this.firstName; }
  55. }
  56. [StringLength(10)]
  57. public String MiddleInitials {
  58. set { this.middleInitials = value; }
  59. get { return this.middleInitials; }
  60. }
  61. [StringLength(50)]
  62. public String LasttName {
  63. set { this.lastName = value; }
  64. get { return this.lastName; }
  65. }
  66. [StringLength(64)]
  67. public String Password {
  68. set { this.password = value; }
  69. get { return this.password; }
  70. }
  71.  
  72.  
  73. public char Gender {
  74. set { this.gender = value; }
  75. get { return this.gender; }
  76. }
  77.  
  78.  
  79. public char Active {
  80. set { this.active = value; }
  81. get { return this.active; }
  82. }
  83.  
  84. public UserModel()
  85. {
  86. }
  87. }
  88. }
  89.  
  90. using System;
  91. using Microsoft.EntityFrameworkCore;
  92.  
  93. namespace WEB_API_DOT_NET_CORE.Model
  94. {
  95. public class CollectionsCatalogContex: DbContext
  96. {
  97. public CollectionsCatalogContex(DbContextOptions<CollectionsCatalogContex> options): base(options)
  98. {
  99. }
  100.  
  101. public DbSet<UserModel> UsersModel { get; set; }
  102. }
  103. }
  104.  
  105. {
  106. "Logging": {
  107. "IncludeScopes": false,
  108. "Debug": {
  109. "LogLevel": {
  110. "Default": "Warning"
  111. }
  112. },
  113. "Console": {
  114. "LogLevel": {
  115. "Default": "Warning"
  116. }
  117. }
  118. },
  119. "MySQLConnString": {
  120. "MySqlConnectionString": "Server=localhost;Port=3306;DataBase=COLLECTIONSCATALOG;Uid=root;Pwd=senha@321"
  121. }
  122. }
  123.  
  124. // This method gets called by the runtime. Use this method to add services to the container.
  125. public void ConfigureServices(IServiceCollection services)
  126. {
  127.  
  128. var connection = Configuration["MySQLConnString:MySqlConnectionString"];
  129. services.AddDbContext<CollectionsCatalogContex>(options =>
  130. options.UseMySQL(connection)
  131. );
  132.  
  133. services.AddMvc();
  134. }
  135.  
  136. using System;
  137. using System.Collections.Generic;
  138. using System.Linq;
  139. using System.Threading.Tasks;
  140. using Microsoft.AspNetCore.Mvc;
  141. using WEB_API_DOT_NET_CORE.Model;
  142.  
  143. namespace WEB_API_DOT_NET_CORE.Controllers
  144. {
  145. [Route("api/[controller]")]
  146. public class UserController : Controller
  147. {
  148.  
  149. private readonly CollectionsCatalogContex context;
  150.  
  151. public UserController(CollectionsCatalogContex context)
  152. {
  153. this.context = context;
  154. }
  155.  
  156. // GET: api/values
  157. [HttpGet]
  158. public IEnumerable<UserModel> Get()
  159. {
  160. return context.UsersModel.ToList<UserModel>();
  161. }
  162.  
  163. // GET api/user/2
  164. [HttpGet("{id}")]
  165. public UserModel Get(int id)
  166. {
  167. return context.UsersModel.Find(id);
  168. }
  169.  
  170. // POST api/values
  171. [HttpPost]
  172. public void Post([FromBody]string value)
  173. {
  174. }
  175.  
  176. // PUT api/values/5
  177. [HttpPut("{id}")]
  178. public void Put(int id, [FromBody]string value)
  179. {
  180. }
  181.  
  182. // DELETE api/values/5
  183. [HttpDelete("{id}")]
  184. public void Delete(int id)
  185. {
  186. }
  187. }
  188. }
  189.  
  190. An unhandled exception occurred while processing the request.
  191. ArgumentOutOfRangeException: Length cannot be less than zero.
  192. Parameter name: length
  193. string.Substring(int startIndex, int length)
  194.  
  195. TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.MySqlConfiguration' threw an exception.
  196. MySql.Data.MySqlClient.MySqlConfiguration.get_Settings()
  197.  
  198. TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.
  199. MySql.Data.MySqlClient.Replication.ReplicationManager.IsReplicationGroup(string groupName)
  200.  
  201. TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.
  202. MySql.Data.MySqlClient.Replication.ReplicationManager.IsReplicationGroup(string groupName)
  203. MySql.Data.MySqlClient.MySqlConnection.Open()
  204. Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(bool errorsExpected)
  205. Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable+Enumerator.BufferlessMoveNext(bool buffer)
  206. Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable+Enumerator.MoveNext()
  207. Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider+<_TrackEntities>d__17.MoveNext()
  208. Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider+ExceptionInterceptor+EnumeratorExceptionInterceptor.MoveNext()
  209. System.Collections.Generic.List.AddEnumerable(IEnumerable<T> enumerable)
  210. System.Linq.Enumerable.ToList<TSource>(IEnumerable<TSource> source)
  211. WEB_API_DOT_NET_CORE.Controllers.UserController.Get() in UserController.cs
  212. -
  213. }
  214. // GET: api/values
  215. [HttpGet]
  216. public IEnumerable<UserModel> Get()
  217. {
  218. return context.UsersModel.ToList<UserModel>();
  219. }
  220. // GET api/user/2
  221. [HttpGet("{id}")]
  222. public UserModel Get(int id)
  223. {
  224. lambda_method(Closure , object , Object[] )
  225. Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(object target, Object[] parameters)
  226. Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeActionMethodAsync>d__12.MoveNext()
  227. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  228. System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  229. Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeNextActionFilterAsync>d__10.MoveNext()
  230. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  231. Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
  232. Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
  233. Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeInnerFilterAsync>d__14.MoveNext()
  234. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  235. System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  236. Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeNextResourceFilter>d__22.MoveNext()
  237. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  238. Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
  239. Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
  240. Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeFilterPipelineAsync>d__17.MoveNext()
  241. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  242. System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  243. Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeAsync>d__15.MoveNext()
  244. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  245. System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  246. Microsoft.AspNetCore.Builder.RouterMiddleware+<Invoke>d__4.MoveNext()
  247. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  248. System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  249. Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+<Invoke>d__7.MoveNext()
Add Comment
Please, Sign In to add comment