예제 #1
0
 public void UpdatePage(Page page)
 {
     db.Entry(page).State = EntityState.Modified;
     foreach (PageDescription dp in page.PageDescriptions)
     {
         db.Entry(dp).State = EntityState.Modified;
     }
     db.SaveChanges();
 }
예제 #2
0
 public void CreateOrder(Order order)
 {
     db.Orders.Add(order);
     db.OrderHasTickets.AddRange(order.OrderHasTickets);
     foreach (OrderHasTickets oht in order.OrderHasTickets)
     {
         oht.Ticket.TimeSlot.OccupiedSeats  += oht.Amount;
         db.Entry(oht.Ticket.TimeSlot).State = EntityState.Modified;
     }
     db.SaveChanges();
 }
예제 #3
0
        public void UpdateActivity(Activity activity)
        {
            for (int i = 0; i < activity.Timeslots.Count; i++)
            {
                if (activity.Timeslots[i].StartTime != activity.Timeslots[i].Tickets[0].TimeSlot_StartTime)
                {
                    TimeSlot newSlot = new TimeSlot();
                    newSlot.Activity_Id             = activity.Timeslots[i].Activity_Id;
                    newSlot.StartTime               = activity.Timeslots[i].StartTime;
                    newSlot.EndTime                 = activity.Timeslots[i].EndTime;
                    newSlot.Tickets                 = activity.Timeslots[i].Tickets;
                    newSlot.TotalSeats              = activity.Timeslots[i].TotalSeats;
                    newSlot.OccupiedSeats           = activity.Timeslots[i].OccupiedSeats;
                    newSlot.Hall                    = activity.Timeslots[i].Hall;
                    activity.Timeslots[i].StartTime = activity.Timeslots[i].Tickets[0].TimeSlot_StartTime;

                    int      actID     = activity.Timeslots[i].Activity_Id;
                    DateTime startTime = activity.Timeslots[i].StartTime;
                    db.TimeSlots.Remove(db.TimeSlots.Where(
                                            time => time.Activity_Id == actID && time.StartTime == startTime).SingleOrDefault()
                                        );
                    db.TimeSlots.Add(newSlot);
                    activity.Timeslots[i] = newSlot;
                    for (int j = 0; j < activity.Timeslots[i].Tickets.Count; j++)
                    {
                        Ticket newTicket = new Ticket();

                        newTicket.TimeSlot_Activity_Id = newSlot.Activity_Id;
                        newTicket.TimeSlot_StartTime   = newSlot.StartTime;
                        newTicket.Price = activity.Timeslots[i].Tickets[j].Price;
                        newTicket.Type  = activity.Timeslots[i].Tickets[j].Type;
                        TicketType type = activity.Timeslots[i].Tickets[j].Type;
                        db.Tickets.Remove(db.Tickets.Where(
                                              ti => ti.TimeSlot_Activity_Id == actID && ti.TimeSlot_StartTime == startTime && ti.Type == type).SingleOrDefault());
                        activity.Timeslots[i].Tickets[j] = newTicket;
                        db.Tickets.Add(newTicket);
                    }
                }
            }
            db.Entry(activity).State = EntityState.Modified;
            foreach (ActivityDescription dp in activity.ActivityDescriptions)
            {
                db.Entry(dp).State = EntityState.Modified;
            }
            foreach (TimeSlot ts in activity.Timeslots)
            {
                if (db.Entry(ts).State != EntityState.Added)
                {
                    db.Entry(ts).State = EntityState.Modified;
                }
                foreach (Ticket ti in ts.Tickets)
                {
                    if (db.Entry(ti).State != EntityState.Added)
                    {
                        db.Entry(ti).State = EntityState.Modified;
                    }
                }
            }
            db.SaveChanges();
        }