public static void deleteBooking(int bookingId) { using (Massage_BookingEntities context = new Massage_BookingEntities()) { context.Bookings.Remove(context.Bookings.First(booking => booking.id == bookingId)); context.SaveChanges(); } }
public static IEnumerable <Massage_Days> getLastWeekDays() { using (Massage_BookingEntities context = new Massage_BookingEntities()) { var massage_days = from m in context.Massage_Days orderby m.date descending select m; return(massage_days.Take(5).ToList()); } }
//public static string getMasseuseName(DateTime massageDay) //{ // using (Massage_BookingEntities context = new Massage_BookingEntities()) // { // var masseuseName = from m in context.Massage_Days // where m.date == massageDay // select m.masseuse; // return masseuseName.FirstOrDefault(); // } //} public static void refreshWeekInDB(IEnumerable <DateTime> weekDays) { try { using (Massage_BookingEntities context = new Massage_BookingEntities()) { string[] hours = { "10:00", "10:20", "10:40", "11:00", "11:20", "11:40", "12:00", "12:20", "12:40", "13:00", "13:20", "13:40", "14:00", "14:20", "14:40", "15:00", "15:20", "15:40", "16:00", "16:20", "16:40" }; string[] masseuseNames = { "Ani", "Ani", "Stefi", "Stefi", "Ani" }; for (var day = 0; day < weekDays.Count(); day++) { Massage_Days newDay = new Massage_Days() { date = weekDays.ElementAt(day), masseuse = masseuseNames[day] }; context.Massage_Days.Add(newDay); context.SaveChanges(); foreach (var hour in hours) { Massage_Slots massageSlot = new Massage_Slots() { massage_day_id = newDay.id, start_hour = DateTime.Parse(hour) }; context.Massage_Slots.Add(massageSlot); } } context.SaveChanges(); } } catch (DbUpdateException ex) { throw; } catch (Exception ex) { throw; } }