Пример #1
0
 public Order GetByID(int orderID)
 {
     using (DB_Car_RentalEntities ctx = new DB_Car_RentalEntities())
     {
         return(ctx.Orders.Where(o => o.OrderID == orderID).FirstOrDefault());
     }
 }
 public User GetByID(int userID)
 {
     using (DB_Car_RentalEntities ctx = new DB_Car_RentalEntities())
     {
         return(ctx.Users.Where(u => u.UserID == userID).FirstOrDefault());
     }
 }
Пример #3
0
 public Cartyp GetCarTypeByID(int CarID)
 {
     using (DB_Car_RentalEntities ctx = new DB_Car_RentalEntities())
     {
         return(ctx.Cartyps.Where(c => c.TypeID == CarID).FirstOrDefault());
     }
 }
Пример #4
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);
            }
        }
Пример #5
0
 public List <Car> GetAll()
 {
     using (DB_Car_RentalEntities ctx = new DB_Car_RentalEntities())
     {
         return(ctx.Cars.Include("Cartyp").Where(c => c.CarID == c.Cartyp.TypeID && c.IsActiv == true || c.Cartyp.IsActiv == true).ToList());
     }
 }
 public List <RolesType> GetRoleForuser(string email)
 {
     using (DB_Car_RentalEntities ctx = new DB_Car_RentalEntities())
     {
         return(ctx.RolesTypes.ToList());
     }
 }
        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);
            }
        }
Пример #8
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);
            }
        }
        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);
            }
        }
Пример #10
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);
            }
        }
 public UserManager()
 {
     ctx = new DB_Car_RentalEntities();
 }
Пример #12
0
 public ManufacturerManager()
 {
     ctx = new DB_Car_RentalEntities();
 }
Пример #13
0
 public BranchManager()
 {
     ctx = new DB_Car_RentalEntities();
 }