Add project files.
This commit is contained in:
20
test/Controllers/HomeController.cs
Normal file
20
test/Controllers/HomeController.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using test.Models;
|
||||
|
||||
namespace test.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
testEntities db = new testEntities();
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
ViewBag.Title = "Home Page";
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
156
test/Controllers/UsersController.cs
Normal file
156
test/Controllers/UsersController.cs
Normal file
@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using test.Models;
|
||||
|
||||
namespace test.Controllers
|
||||
{
|
||||
public class UsersController : Controller
|
||||
{
|
||||
private testEntities db = new testEntities();
|
||||
|
||||
// GET: Users
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View(db.Users.ToList());
|
||||
}
|
||||
|
||||
// GET: Users/Details/5
|
||||
public ActionResult Details(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
User user = db.Users.Find(id);
|
||||
if (user == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
return View(user);
|
||||
}
|
||||
|
||||
// GET: Users/signUp
|
||||
public ActionResult Create()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
// POST: Users/signUp
|
||||
// To protect from overposting attacks, enable the specific properties you want to bind to, for
|
||||
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Create([Bind(Include = "User_ID,User_Name,User_LastName,User_PhoneNumber,User_Password,User_Status")] User user)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
db.Users.Add(user);
|
||||
db.SaveChanges();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
return View(user);
|
||||
}
|
||||
|
||||
// GET: Users/Edit/5
|
||||
public ActionResult Edit(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
User user = db.Users.Find(id);
|
||||
if (user == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
return View(user);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// GET: Users/Login
|
||||
public ActionResult Login()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
// POST: Users/Login
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Login(string User_PhoneNumber, string User_Password)
|
||||
{
|
||||
var user = db.Users.FirstOrDefault(u => u.User_PhoneNumber == User_PhoneNumber && u.User_Password == User_Password);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
// ذخیره اطلاعات کاربر در Session
|
||||
Session["UserID"] = user.User_ID;
|
||||
Session["UserName"] = user.User_Name;
|
||||
|
||||
// انتقال به صفحه اصلی
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
ViewBag.Message = "شماره یا رمز عبور اشتباه است.";
|
||||
return View();
|
||||
}
|
||||
|
||||
// POST: Users/Edit/5
|
||||
// To protect from overposting attacks, enable the specific properties you want to bind to, for
|
||||
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Edit([Bind(Include = "User_ID,User_Name,User_LastName,User_PhoneNumber,User_Password,User_Status")] User user)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
db.Entry(user).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
return View(user);
|
||||
}
|
||||
|
||||
// GET: Users/Delete/5
|
||||
public ActionResult Delete(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
User user = db.Users.Find(id);
|
||||
if (user == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
return View(user);
|
||||
}
|
||||
|
||||
// POST: Users/Delete/5
|
||||
[HttpPost, ActionName("Delete")]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult DeleteConfirmed(int id)
|
||||
{
|
||||
User user = db.Users.Find(id);
|
||||
db.Users.Remove(user);
|
||||
db.SaveChanges();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
db.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
test/Controllers/ValuesController.cs
Normal file
39
test/Controllers/ValuesController.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace test.Controllers
|
||||
{
|
||||
public class ValuesController : ApiController
|
||||
{
|
||||
// GET api/values
|
||||
public IEnumerable<string> Get()
|
||||
{
|
||||
return new string[] { "value1", "value2" };
|
||||
}
|
||||
|
||||
// GET api/values/5
|
||||
public string Get(int id)
|
||||
{
|
||||
return "value";
|
||||
}
|
||||
|
||||
// POST api/values
|
||||
public void Post([FromBody] string value)
|
||||
{
|
||||
}
|
||||
|
||||
// PUT api/values/5
|
||||
public void Put(int id, [FromBody] string value)
|
||||
{
|
||||
}
|
||||
|
||||
// DELETE api/values/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user