Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using React_01.Models;
- namespace React_01.Controllers
- {
- public class HomeController : Controller
- {
- private static readonly IList<UserModel> users;
- public IActionResult Index()
- {
- return View();
- }
- public IActionResult About()
- {
- ViewData["Message"] = "Your application description page.";
- return View();
- }
- public IActionResult Contact()
- {
- ViewData["Message"] = "Your contact page.";
- return View();
- }
- public IActionResult Error()
- {
- return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
- }
- // --- Login ---
- [Route("Home/login")]
- [HttpPost]
- public ActionResult Login(UserModel user)
- {
- var userBuff = users.FirstOrDefault(item => item.Name == user.Name);
- if (userBuff == null)
- {
- return Content("User not found");
- }
- else
- {
- if (userBuff.Password == user.Password)
- {
- // return Content("User logged");
- // return Json(user);
- return Json(new{succes = true, User = user, message = user.Name + " " + user.Id});
- }
- else
- {
- return Content("Wrong password");
- }
- }
- }
- [HttpGet]
- public JsonResult GetOrderForAdd()
- {
- return Json("test");
- }
- // --- AddUser ---
- [Route("users/new")]
- [HttpPost]
- public ActionResult AddUser(UserModel user)
- {
- user.Id = users.Count + 1;
- users.Add(user);
- return Content("User added");
- }
- // --- Users ---
- [Route("users")]
- [ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
- public ActionResult Users()
- {
- return Json(users);
- }
- static HomeController()
- {
- users = new List<UserModel>
- {
- new UserModel
- {
- Id = 1,
- Name = "juan",
- Password = "12345"
- },
- new UserModel
- {
- Id = 2,
- Name = "juan2",
- Password = "1234567"
- },
- new UserModel
- {
- Id = 3,
- Name = "juan3",
- Password = "999999999"
- },
- };
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement