Exemple #1
0
        public ActionResult Delete(int id)
        {
            using (var dbContext = new shopDbContext())
            {
                var model = dbContext.Cars
                            .FirstOrDefault(p => p.ID == id);

                dbContext.Entry(model).State = EntityState.Deleted;
                dbContext.SaveChanges();

                return(Json(new { isSuccess = true }));
            }
        }
Exemple #2
0
        public ActionResult Create(Car model)
        {
            if (ModelState.IsValid)
            {
                var dbContext = new shopDbContext();
                dbContext.Cars.Add(model);
                dbContext.SaveChanges();

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(model));
            }
        }
Exemple #3
0
        public ActionResult EditPost(int id)
        {
            using (var dbContext = new shopDbContext()) {
                var model = dbContext.Kupci
                            .FirstOrDefault(p => p.ID == id);

                var didUpdateModelSucceed = this.TryUpdateModel(model);

                if (didUpdateModelSucceed && ModelState.IsValid)
                {
                    dbContext.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                return(View(model));
            }
        }
Exemple #4
0
        public ActionResult Create(Narudzbe model)
        {
            if (ModelState.IsValid)
            {
                var dbContext = new shopDbContext();

                var data = dbContext.Cars
                           .ToList();
                int carId = (int)model.CarId;
                var car   = data.FirstOrDefault(p => p.ID == carId);

                model.cijena = Izracun.izracunaj(car.SellPrice, 500);
                dbContext.Orders.Add(model);
                dbContext.SaveChanges();

                return(RedirectToAction("Index"));
            }
            else
            {
                this.FillDropDownValues();
                return(View(model));
            }
        }