Exemplo n.º 1
0
        public bool Insert(Car newCar, Cartyp newcartype)
        {
            using (DB_Car_RentalEntities ctx = new DB_Car_RentalEntities())
            {
                ctx.Cars.Add(newCar);

                ctx.Cartyps.Add(newcartype);

                int count = ctx.SaveChanges();


                return(count > 0);
            }
        }
Exemplo n.º 2
0
        // GET: Cars/Create
        public ActionResult Create(CarsViewModel cVM)
        {
            // 1) validate the user details
            if (ModelState.IsValid)
            {
                Cartyp newctp = new Cartyp
                {
                    TypeID               = cVM.TypeID,
                    Manufacturer         = cVM.Manufacturer,
                    Model                = cVM.Model,
                    Year_of_Manufacturer = cVM.Year_of_Manufacturer,
                    Transmission         = cVM.Transmission,
                    Daily_cost           = cVM.Daily_cost,
                    Day_late             = cVM.Daily_cost,
                    IsActiv              = true
                };

                Car newc = new Car
                {
                    CarID            = cVM.CarID,
                    Mileage          = cVM.Mileage,
                    Picture          = cVM.Picture,
                    IsRepaired       = cVM.IsRepaired,
                    IsAvailable      = cVM.IsAvailable,
                    C_License_number = cVM.C_License_number,
                    BranchID         = cVM.BranchID,
                    IsActiv          = true
                };

                // 2) update the student in db
                carsmanager.Insert(newc, newctp);
                //db.SaveChanges();

                // 3) return to list of all student
                return(RedirectToAction("CartypsAndCar"));
            }
            else
            {
                //  חוזרים לאותו הוויו עם אותו המודל
                // ולא העתק שלו!!!!
                return(View("Index"));
            }
        }