public List<ReservationsByDate> GetReservationsByDate(string reservationDate) { using (var context = new eRestaurantContext()) { //Linq is not very playfull or cooperative with //Date Time //extract the year, month and day ourselfs //out of the passed parameter value int theYear = (DateTime.Parse(reservationDate)).Year; int theMonth = (DateTime.Parse(reservationDate)).Month; int theDay = (DateTime.Parse(reservationDate)).Day; var results = from eventItem in context.SpecialEvents orderby eventItem.Description select new ReservationsByDate() //a new instance for each specialEvent row on the table { Description = eventItem.Description, Reservations = from row in eventItem.Reservations where row.ReservationDate.Year == theYear && row.ReservationDate.Month == theMonth && row.ReservationDate.Day == theDay select new ReservationDetail() // a new instance for each reservation of a particular specialEvent code. { CustomerName = row.CustomerName, ReservationDate = row.ReservationDate, NumberInParty = row.NumberInParty, ContactPhone = row.ContactPhone, ReservationStatus = row.ReservationStatus } }; return results.ToList(); } }
public DateTime GetLastBillDateTime() { using (var context = new eRestaurantContext()) { var result = context.Bills.Max(eachBillrow => eachBillrow.BillDate); return result; } }
public List<Reservation> GetReservationsByEventCode(string eventcode) { // connect to our DbContext class in the DAL // create and instance of the class. // we will use a transaction to hold our query using (var context = new eRestaurantContext()) { //Query Syntax var results = from item in context.Reservations where item.EventCode.Equals(eventcode) orderby item.CustomerName, item.ReservationDate select item; return results.ToList(); } }
public Waiter GetWaiterByID(int waiterid) { // connect to our DbContext class in the DAL // create and instance of the class. // we will use a transaction to hold our query using (var context = new eRestaurantContext()) { // method syntax //return context.SpecialEvents.OrderBy(x => x.Description).ToList(); //Query Syntax var results = from item in context.Waiters where item.WaiterID == waiterid select item; return results.FirstOrDefault(); // one row at most } }
public void Waiter_Update(Waiter item) { using (eRestaurantContext context = new eRestaurantContext()) { // Indicate the updating item instance // alter the Modified Status flag for this instance context.Entry<Waiter>(context.Waiters.Attach(item)).State = System.Data.Entity.EntityState.Modified; // command is not executed until it is actually saved. context.SaveChanges(); } }
public void Waiter_Delete(Waiter item) { using (eRestaurantContext context = new eRestaurantContext()) { // Lookup the instance and record if found Waiter existing = context.Waiters.Find(item.WaiterID); // Setup the command to execute the delete context.Waiters.Remove(existing); //command is not executed until it is actually saved. context.SaveChanges(); } }
public List<Waiter> Waiters_List() { // connect to our DbContext class in the DAL // create and instance of the class. // we will use a transaction to hold our query using (var context = new eRestaurantContext()) { // method syntax //return context.SpecialEvents.OrderBy(x => x.Description).ToList(); //Query Syntax var results = from item in context.Waiters orderby item.LastName, item.FirstName select item; return results.ToList(); //none, 1 or more rows } }
public int Waiters_Add(Waiter item) { using (eRestaurantContext context = new eRestaurantContext()) { /* These methods are executed using an instance level item * set up a instance pointer and initialize to null */ Waiter added = null; // setup the command to execute the add added = context.Waiters.Add(item); // command is not executed until it is actually saved. context.SaveChanges(); // The waiter instance added contains the newly inserted // record to sql including the generated primary key value return added.WaiterID; } }
public void SpecialEvents_Delete(SpecialEvent item) { using (eRestaurantContext context = new eRestaurantContext()) { // Lookup the instance and record if found SpecialEvent existing = context.SpecialEvents.Find(item.EventCode); // Setup the command to execute the delete context.SpecialEvents.Remove(existing); //command is not executed until it is actually saved. context.SaveChanges(); } }
public void SpecialEvents_ADD(SpecialEvent item) { using (eRestaurantContext context = new eRestaurantContext()) { /* These methods are executed using an instance level item * set up a instance pointer and initialize to null */ SpecialEvent added = null; // setup the command to execute the add added = context.SpecialEvents.Add(item); // command is not executed until it is actually saved. context.SaveChanges(); } }