コード例 #1
0
 //adds a massage day to the database
 public static void addMassageDay(Massage_Days msDay)
 {
     using (Massage_BookingEntities context = new Massage_BookingEntities())
     {
         context.Massage_Days.Add(msDay);
         context.SaveChanges();
     }
 }
コード例 #2
0
 //removes a massage day from the database
 public static void removeMassageDay(int dayID)
 {
     using (Massage_BookingEntities context = new Massage_BookingEntities())
     {
         Massage_Days mday = context.Massage_Days.Find(dayID);
         context.Massage_Days.Remove(mday);
         context.SaveChanges();
     }
 }
コード例 #3
0
        //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;
            }
        }