public ActionResult EditModesAddNewPartial(Car car) { if (ModelState.IsValid) { try { //NorthwindDataProvider.InsertProduct(product); using (var data = new Provider()) { car.Location = data.LocationRepository.GetLocationById(car.Location.Id); data.CarRepository.Add(car); } } catch (Exception e) { ViewData["EditError"] = e.Message; } } else ViewData["EditError"] = "Please, correct all errors."; using (var data = new Provider()) { return PartialView("EditCarPartial", data.CarRepository.GetAllCar()); } //return PartialView("EditModesPartial", NorthwindDataProvider.GetEditableProducts()); }
public void Add(Car newCar) { using (ISession session = NHibernateHelper.OpenSession()) { using( ITransaction transaction = session.BeginTransaction()) { session.Save(newCar); transaction.Commit(); } } }
public ActionResult AddCarSave(CarModel car) { var c = new Car(); c.Made = car.Made; c.NumberOfOwners = car.NumberOfOwners; c.ProductionTime = DateTime.Now; c.Type = car.Type; c.Condition = car.Condition; using (var data = new Provider()) { c.Location = data.LocationRepository.GetLocationById( car.LocationId ); data.CarRepository.Add(c); return View("ListLocationsForCars", data.LocationRepository.GetAllLocation()); } }
public void Delete(Car newCar) { using (ISession session = NHibernateHelper.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { try { session.Delete(newCar); transaction.Commit(); } catch (Exception) { transaction.Commit(); } } } }
public ActionResult EditModesDeletePartial(Car car) { if (car.Id >= 0) { try { //NorthwindDataProvider.DeleteProduct(productID); using (var data = new Provider()) { data.CarRepository.DeleteCarById(car.Id); } } catch (Exception e) { ViewData["EditError"] = e.Message; } } //return PartialView("EditModesPartial", NorthwindDataProvider.GetEditableProducts()); using (var data = new Provider()) { return PartialView("EditCarPartial", data.CarRepository.GetAllCar()); } }