public ActionResult LogIn(Anketa_Proekt.Models.Louse user) { //if (ModelState.IsValid) //{ if (user.isValidUser(user.e_mail, user.lozinka)) { //FormsAuthentication.SetAuthCookie(user.e_mail, true); //FormsAuthentication.SetAuthCookie() using (var db = new AnketiEntities5()) { var query = from a in db.Lice where a.e_mail.Equals(user.e_mail) & a.lozinka.Equals(user.lozinka) select a.id_lice; int idLice = query.FirstOrDefault(); Session["id_lice"] = idLice; return(RedirectToAction("Index", "Anketa")); } } else { ModelState.AddModelError("", "Login data is incorrect!"); } //} return(View(user)); }
public UserController() { this.MainLayoutViewModel = new Anketa_Proekt.Models.Louse();//has property PageTitle //this.MainLayoutViewModel. = "my title"; this.ViewData["MainLayoutViewModel"] = this.MainLayoutViewModel; }
public ActionResult Registration(Anketa_Proekt.Models.Louse user) { using (var db = new AnketiEntities5()) { List <SelectListItem> listSelectListItems = new List <SelectListItem>(); foreach (Grad city in db.Grads) { SelectListItem selectList = new SelectListItem() { Text = city.ime_grad, Value = city.id_grad.ToString(), //Selected = false }; listSelectListItems.Add(selectList); } ViewBag.MyGradovi = listSelectListItems; //return View(); } if (ModelState.IsValid) { using (var db = new AnketiEntities5()) { var newUser = db.Lice.Create(); newUser.ime = user.ime; newUser.prezime = user.prezime; newUser.e_mail = user.e_mail; newUser.lozinka = user.lozinka; newUser.tel_broj = user.tel_broj; newUser.ulica = user.ulica; newUser.id_grad = user.id_grad; newUser.datum_r = user.datum_r; db.Lice.Add(newUser); db.SaveChanges(); Session["id_lice"] = newUser.id_lice; var korisnik = db.Korisniks.Create(); korisnik.id_lice = newUser.id_lice; korisnik.br_anketi = 0; db.Korisniks.Add(korisnik); db.SaveChanges(); return(RedirectToAction("Index", "Anketa")); } } else { ModelState.AddModelError("", "The data that you Entered is incorrect!"); } return(View()); }