Example #1
0
 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());
 }
Example #2
0
 public void Add(Car newCar)
 {
     using (ISession session = NHibernateHelper.OpenSession())
     {
         using( ITransaction transaction = session.BeginTransaction())
         {
             session.Save(newCar);
             transaction.Commit();
         }
     }
 }
Example #3
0
        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());
            }
        }
Example #4
0
        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();
                    }

                }
            }
        }
Example #5
0
 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());
     }
 }