Пример #1
0
        public bool SaveCustomerDetails(Customer customer) // calling SaveStudentMethod for insert a new record
        {
            bool result = false;

            using (CustomerEntities _entity = new CustomerEntities())
            {
                _entity.Customer.Add(customer);
                _entity.SaveChanges();
                result = true;
            }
            return(result);
        }
        public bool DeleteFlightDetails(Flight flight) // DeleteStudentDetails method to delete record from table
        {
            bool result = false;

            using (CustomerEntities _entity = new CustomerEntities())
            {
                //Flight book = (Flight)_entity.Flight.Where(b => b.flightId == flight.flightId).First();
                //_entity.DeleteObject(book);
                Flight _flight = _entity.Flight.Where(x => x.flightId == flight.flightId).Select(x => x).FirstOrDefault();
                _entity.Flight.Remove(_flight);
                _entity.SaveChanges();
                result = true;
            }
            return(result);
        }
 public void Display()   // Display Method is a common method to bind the Student details in datagridview after save,update and delete operation perform.
 {
     using (CustomerEntities _entity = new CustomerEntities())
     {
         List <FlightClass> _flightList = new List <FlightClass>();
         _flightList = _entity.Flight.Select(x => new FlightClass
         {
             flightId       = x.flightId,
             airlineCompany = x.airlineCompany,
             origin         = x.origin,
             destination    = x.destination,
             date           = x.date
         }).ToList();
         FlightDataGridView.DataSource = _flightList;
     }
 }
        public bool UpdateFlightDetails(Flight flight) // UpdateStudentDetails method for update a existing Record
        {
            bool result = false;

            using (CustomerEntities _entity = new CustomerEntities())
            {
                Flight _flight = _entity.Flight.Where(x => x.flightId == flight.flightId).Select(x => x).FirstOrDefault();
                _flight.airlineCompany = flight.airlineCompany;
                _flight.origin         = flight.origin;
                _flight.destination    = flight.destination;
                _flight.date           = flight.date;
                _entity.SaveChanges();
                result = true;
            }
            return(result);
        }
 private void FlightForm_Load(object sender, EventArgs e)
 {
     _customerEntities = new CustomerEntities();
     Display();
 }