コード例 #1
0
        public bool Update(Car carToUpdate)
        {
            using (DB_Car_RentalEntities ctx = new DB_Car_RentalEntities())
            {
                // option 1: find the employee, update the properties, save cahnges
                //var e = ctx.Employees.Find(employeeToUpdate.EmployeeID);
                //e.FirstName = employeeToUpdate.FirstName;
                //e = employeeToUpdate;

                // option 2: -- need to make the ctx as data member
                //var e = GetByID(employeeToUpdate.EmployeeID);
                //e.FirstName = employeeToUpdate.FirstName;
                //e = employeeToUpdate;

                // option 3: add the employee to the context

                // 1) attach the employee to the context (in the memory)
                ctx.Cars.Attach(carToUpdate);

                // 2) mark the employee as "need to be updated"
                ctx.Entry(carToUpdate).State = System.Data.EntityState.Modified;

                // 3) save the changes in the database
                int count = ctx.SaveChanges();

                return(count > 0);
            }
        }
コード例 #2
0
        public bool deleteTest(Car carToDelete)
        {
            var c     = ctx.Cars.Include("Cartyp").Where(ca => ca.CarID == ca.Cartyp.TypeID);
            int count = ctx.SaveChanges();

            return(count > 0);
        }
コード例 #3
0
        public bool Insert(User newUser)
        {
            using (DB_Car_RentalEntities ctx = new DB_Car_RentalEntities())
            {
                ctx.Users.Add(newUser);
                int count = ctx.SaveChanges();

                return(count > 0);
            }
        }
コード例 #4
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);
            }
        }
コード例 #5
0
        public bool Update(User userToUpdate)
        {
            using (DB_Car_RentalEntities ctx = new DB_Car_RentalEntities())
            {
                // 1) attach the employee to the context (in the memory)
                ctx.Users.Attach(userToUpdate);

                // 2) mark the employee as "need to be updated"
                ctx.Entry(userToUpdate).State = System.Data.EntityState.Modified;

                // 3) save the changes in the database
                int count = ctx.SaveChanges();

                return(count > 0);
            }
        }
コード例 #6
0
        public bool Delete(Order orderToDelete)
        {
            using (DB_Car_RentalEntities ctx = new DB_Car_RentalEntities())
            {
                // 1) attach the employee to the context (in the memory)
                ctx.Orders.Attach(orderToDelete);

                // 2) mark the employee as "need to be updated"
                ctx.Entry(orderToDelete).State = System.Data.EntityState.Modified;
                if (orderToDelete.IsActiv == true)
                {
                    orderToDelete.IsActiv = false;
                }

                // 3) save the changes in the database
                int count = ctx.SaveChanges();

                return(count > 0);
            }
        }