Guest User

LoginControlller.cs

a guest
Nov 16th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.Http;
  6. using System.Web.Http;
  7. using System.Web.Http.Cors;
  8. using webService.DB;
  9. using webService.Models;
  10.  
  11. namespace webService.Controllers
  12. {
  13.     [EnableCors(origins: "http://localhost:8100", headers: "*", methods: "get,post")]
  14.     public class LoginController : ApiController
  15.     {
  16.  
  17.         [Route("api/login/GetData/{username}/{password}")]
  18.         public HttpResponseMessage GetData(string username, string password)
  19.         {
  20.            
  21.  
  22.             using (VodovodEntities db = new VodovodEntities())
  23.             {
  24.                 List<users> allUsers = db.users.Where(t => t.username == username.Trim() && t.password ==password.Trim()).ToList();
  25.  
  26.                 if (allUsers.Count != 0)
  27.                 {
  28.  
  29.                     return Request.CreateResponse(HttpStatusCode.OK, "Login succedeed.");
  30.                 }
  31.  
  32.                 return Request.CreateResponse(HttpStatusCode.NotFound, "Login failed.");
  33.             }
  34.         }
  35.  
  36.        
  37.  
  38.      
  39.  
  40.         // POST api/values
  41.         public void Post([FromBody]string value)
  42.         {
  43.         }
  44.  
  45.         // PUT api/values/5
  46.         public void Put(int id, [FromBody]string value)
  47.         {
  48.         }
  49.  
  50.         // DELETE api/values/5
  51.         public void Delete(int id)
  52.         {
  53.         }
  54.     }
  55.  
  56. }
Add Comment
Please, Sign In to add comment