Cant edit my post god damit..
Anyways, i found this solution, i combined few tutorials from google search and i came on this one:
Controller:
PHP Code
<?php
using RegistrationLoginForm.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace RegistrationLoginForm.Controllers
{
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
// Register
[HttpGet]
public ActionResult Register()
{
return View();
}
[HttpPost]
public ActionResult Register(People user)
{
if (ModelState.IsValid)
{
using (PeopleDBContext cont = new PeopleDBContext())
{
cont.PeopleCon.Add(user);
cont.SaveChanges();
ModelState.Clear();
user = null;
}
}
return View(user);
}
// Login
[HttpGet]
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(People user)
{
if (isValid(user.Email, user.Password))
{
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "Wrong data");
}
// return user model/object to the view
return View(user);
}
// Check if user is valid (exists in database etc..)
private bool isValid(string email, string password)
{
bool isValid = false;
using (PeopleDBContext db = new PeopleDBContext())
{
// take user from database
var user = db.PeopleCon.FirstOrDefault(u => u.Email == email);
// if user exists
if (user != null)
{
// if the password from database matches the typed password
if (user.Password == password)
{
isValid = true;
}
}
}
return isValid;
}
}
}
Model:
PHP Code
<?php
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RegistrationLoginForm.Models
{
public class People
{
// Required for database creation - Code First!
public int Id { get; set; }
[Required]
[StringLength(20)]
public string Name { get; set; }
[Required]
[StringLength(20)]
public string Surname { get; set; }
[Required]
[EmailAddress]
[StringLength(150)]
[Display(Name = "Email address: ")] // this will be passed to the View
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
[StringLength(20, MinimumLength = 6)]
[Display(Name = "Password: ")] // pass this value to the View
public string Password { get; set; }
}
}
The rest of the code isnt really important i guess.
So, how about this one? Is it good enough for start?
But of course, i have to crypt some values (like passwords), do some additional checking (if email already exists in database, password confirmation and so on)
My focus was on storing and taking data to/from database at most part.