コード例 #1
0
        public ActionResult Add(AddDriverVM model)
        {
            using (TruckTransportDbContext _db = new TruckTransportDbContext())
            {
                if (_db.vozaci.AsNoTracking().Where(x => x.jmbg == model.PersonUniqueID).FirstOrDefault() != null)
                {
                    ModelState.AddModelError("", "Vozač sa unesenim JMBG-om je već registrovan u sistemu!");
                }

                if (_db.vozaci.AsNoTracking().Where(x => x.user == model.Username).FirstOrDefault() != null)
                {
                    ModelState.AddModelError("", "Korisničko ime se već koristi!");
                }

                if (ModelState.IsValid)
                {
                    vozaci newDriverDB = new vozaci
                    {
                        ime     = model.FirstName,
                        prezime = model.LastName,
                        jmbg    = model.PersonUniqueID,
                        user    = model.Username,
                        pass    = model.Password
                    };

                    _db.vozaci.Add(newDriverDB);
                    _db.SaveChanges();

                    return(Json(data: new { success = true }));
                }
            }

            return(PartialView(viewName: "_Add", model: model));
        }
コード例 #2
0
        public ActionResult Add()
        {
            AddDriverVM model = new AddDriverVM();

            return(PartialView(viewName: "_Add", model: model));
        }