public IActionResult Create(Truck newTruck)
        {
            if (ModelState.IsValid == false)
            {
                return(View("New"));
            }

            newTruck.UserId = (int)uid;
            db.Trucks.Add(newTruck);
            db.SaveChanges();
            return(RedirectToAction("Trucks"));
        }
Beispiel #2
0
        public IActionResult Registering(User newUser)
        {
            if (ModelState.IsValid)
            {
                if (db.Users.Any(u => u.Email == newUser.Email))
                {
                    ModelState.AddModelError("Email", "is Taken");
                }
            }
            if (ModelState.IsValid == false)
            {
                return(View("Register"));
            }

            PasswordHasher <User> hasher = new PasswordHasher <User>();

            newUser.Password = hasher.HashPassword(newUser, newUser.Password);
            db.Users.Add(newUser);
            db.SaveChanges();
            HttpContext.Session.SetInt32("UserId", newUser.UserId);
            HttpContext.Session.SetString("UserName", newUser.FirstName);

            return(RedirectToAction("Trucks", "Trucks"));
        }
Beispiel #3
0
 public void AddMany(List <Truck> model)
 {
     _context.Trucks.AddRange(model);
     _context.SaveChanges();
 }