public static void Auto_Cancel() { using (var db = new DBConnection()) { var reservation = db.DbReservation.Where(item => item.checkin == false && item.cancel == false).ToList(); for (int i = 0; i < reservation.Count; i++) { int time_count = DateTime.Now.TimeOfDay.Subtract(reservation[i].time_create.TimeOfDay).Hours; /* AUTO DELETE RESERVATION AFTER 12 HOURS WITH TABLE 10 SEATS */ if (reservation[i].seats == 10 && time_count > 12) { reservation[i].cancel = true; MemberShipAction.Decreate_Score(reservation[i].customer_telephone, 15); db.Entry(reservation[i]).State = EntityState.Modified; db.SaveChanges(); } /* AUTO DELETE RESERVATION AFTER 5 HOURS WITH TABLE 5 SEATS */ if (reservation[i].seats == 5 && time_count > 5) { reservation[i].cancel = true; MemberShipAction.Decreate_Score(reservation[i].customer_telephone, 10); db.Entry(reservation[i]).State = EntityState.Modified; db.SaveChanges(); } } db.Dispose(); } }
public static void Create_Reservation(string Customer_Phone, int Id_Table) { using (var db = new DBConnection()) { db.DbReservation.Add(new TableReservation { customer_telephone = Customer_Phone, id_table = Id_Table, flag = false, cancel = false, seats = TableAction.Find_Table_By_ID(Id_Table).seats, fullname = MemberShipAction.Find_MemberShip_By_Phone(Customer_Phone).fullname, time_create = DateTime.Now, checkin = false }); db.SaveChanges(); db.Dispose(); } }