Beispiel #1
0
        public ActionResult Edit(EditKnownLocationVM model)
        {
            using (TruckTransportDbContext _db = new TruckTransportDbContext())
            {
                if (_db.poznatelokacije.AsNoTracking().Where(x => (x.naziv == model.Name || (x.sirina == model.Latitude && x.duzina == model.Longitude)) && x.poznatalokacija_id != model.KnownLocationID).FirstOrDefault() != null)
                {
                    ModelState.AddModelError("", "Lokacija sa unesenim nazivom ili pozicijom na karti već postoji!");
                }

                if (ModelState.IsValid)
                {
                    poznatelokacije knownLocationDB = _db.poznatelokacije.Where(x => x.poznatalokacija_id == model.KnownLocationID).FirstOrDefault();

                    knownLocationDB.naziv         = model.Name;
                    knownLocationDB.opis          = model.Description;
                    knownLocationDB.kategorija_id = model.LocationCategoryID;
                    knownLocationDB.sirina        = model.Latitude;
                    knownLocationDB.duzina        = model.Longitude;

                    _db.SaveChanges();

                    return(RedirectToAction(actionName: "Index"));
                }
            }

            model.LocationCategories = _dropdownMaker.GetLocationCategories();
            return(View(viewName: "Edit", model: model));
        }
Beispiel #2
0
        public ActionResult Edit(int knownLocationID)
        {
            EditKnownLocationVM model = new EditKnownLocationVM();

            using (TruckTransportDbContext _db = new TruckTransportDbContext())
            {
                poznatelokacije knownLocation = _db.poznatelokacije.AsNoTracking().Where(x => x.poznatalokacija_id == knownLocationID).FirstOrDefault();

                if (knownLocation != null)
                {
                    model.KnownLocationID    = knownLocation.poznatalokacija_id;
                    model.Name               = knownLocation.naziv;
                    model.Description        = knownLocation.opis;
                    model.LocationCategoryID = knownLocation.kategorija_id;
                    model.Latitude           = knownLocation.sirina;
                    model.Longitude          = knownLocation.duzina;
                }

                model.LocationCategories = _dropdownMaker.GetLocationCategories();
            }

            return(View(viewName: "Edit", model: model));
        }