Exemplo n.º 1
0
        public static void deleteById(int id)
        {
            using (var context = new EventContainer())
            {
                Event e = getByID(id);

                // Now we have SubEvents, delete them first to break relationships with Event object.
                List <SubEvent> subEvents = DomainModels.SubEventModel.getAllByEventID(id);

                foreach (SubEvent s in subEvents)
                {
                    DomainModels.SubEventModel.deleteById(s.Id);
                }

                // ...and BudgetItems too!
                List <BudgetItem> budgetItems = DomainModels.BudgetItemModel.getByBudgetId(e.Budget.Id);

                foreach (BudgetItem b in budgetItems)
                {
                    DomainModels.BudgetItemModel.deleteById(b.Id);
                }

                // Now we can delete both Event and Budget objects in peace.
                // Refresh the Event object by getting from the database again.
                e = getByID(id);

                context.Events.Attach(e);
                context.Budgets.Attach(e.Budget);

                context.Entry(e.Budget).State = EntityState.Deleted;
                context.Entry(e).State        = EntityState.Deleted;

                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public static Event updateObj(Event e)
        {
            using (var context = new EventContainer())
            {
                context.Budgets.Attach(e.Budget);

                context.Entry(e.Budget).State = EntityState.Modified;
                context.Entry(e).State        = EntityState.Modified;

                context.SaveChanges();

                return(e);
            }
        }
        public static BudgetItem updateObj(BudgetItem e)
        {
            using (var context = new EventContainer())
            {
                context.Entry(e).State = EntityState.Modified;
                context.SaveChanges();

                return(e);
            }
        }
Exemplo n.º 4
0
        public static Venue updateObj(Venue e)
        {
            using (var context = new EventContainer())
            {
                context.Entry(e).State = EntityState.Modified;
                context.SaveChanges();

                return e;
            }
        }
Exemplo n.º 5
0
        public static SubEvent updateObj(SubEvent e)
        {
            e.Venue = DBLayer.DomainModels.VenueModel.getByID(e.VenueId);

            using (var context = new EventContainer())
            {
                context.Entry(e).State = EntityState.Modified;
                context.SaveChanges();

                return(e);
            }
        }
 public static Budget update(int allocatedBudget)
 {
     using (var context = new EventContainer())
     {
         Budget budget = new Budget
         {
             AllocatedBudget = allocatedBudget
         };
         context.Budgets.Attach(budget);
         context.Entry(budget).State = EntityState.Modified;
         context.SaveChanges();
         return budget;
     }
 }
 public static Budget update(int id, int allocatedBudget)
 {
     using (var context = new EventContainer())
     {
         Budget budget = new Budget
         {
             Id = id,
             AllocatedBudget = allocatedBudget
         };
         context.Budgets.Attach(budget);
         context.Entry(budget).State = EntityState.Modified;
         context.SaveChanges();
         return(budget);
     }
 }
 public static Venue update(string name, int capacity)
 {
     using (var context = new EventContainer())
     {
         Venue venue = new Venue
         {
             Name = name,
             Capacity = capacity
         };
         context.Venues.Attach(venue);
         context.Entry(venue).State = EntityState.Modified;
         context.SaveChanges();
         return venue;
     }
 }
 public static Venue update(int id, string name, int capacity)
 {
     using (var context = new EventContainer())
     {
         Venue venue = new Venue
         {
             Id       = id,
             Name     = name,
             Capacity = capacity
         };
         context.Venues.Attach(venue);
         context.Entry(venue).State = EntityState.Modified;
         context.SaveChanges();
         return(venue);
     }
 }
 public static BudgetItem update(String name, int cost, int budgetId)
 {
     using (var context = new EventContainer())
     {
         BudgetItem item = new BudgetItem
         {
             Name = name,
             Cost = cost,
             BudgetId = budgetId
         };
         context.BudgetItems.Attach(item);
         context.Entry(item).State = EntityState.Modified;
         context.SaveChanges();
         return item;
     }
 }
 public static BudgetItem update(int id, String name, int cost, int budgetId)
 {
     using (var context = new EventContainer())
     {
         BudgetItem item = new BudgetItem
         {
             Id       = id,
             Name     = name,
             Cost     = cost,
             BudgetId = budgetId
         };
         context.BudgetItems.Attach(item);
         context.Entry(item).State = EntityState.Modified;
         context.SaveChanges();
         return(item);
     }
 }
 public static SubEvent update(int eventId, int venueId, DateTime start, DateTime end)
 {
     using (var context = new EventContainer())
     {
         SubEvent subEvent = new SubEvent
         {
             EventId = eventId,
             Start = start,
             End = end,
             VenueId = venueId,
         };
         context.SubEvents.Attach(subEvent);
         context.Entry(subEvent).State = EntityState.Modified;
         context.SaveChanges();
         return subEvent;
     }
 }
Exemplo n.º 13
0
 public static SubEvent update(int id, int eventId, int venueId, DateTime start, DateTime end, string name = "")
 {
     using (var context = new EventContainer())
     {
         SubEvent subEvent = new SubEvent
         {
             Id      = id,
             Name    = name,
             EventId = eventId,
             Start   = start,
             End     = end,
             VenueId = venueId,
         };
         context.SubEvents.Attach(subEvent);
         context.Entry(subEvent).State = EntityState.Modified;
         context.SaveChanges();
         return(subEvent);
     }
 }
Exemplo n.º 14
0
 public static Event update(int id, string matricId, string name, int venueId, DateTime start, DateTime end, int capacity, int budget = 0, string description = "", short viewAtLoginPage = 1)
 {
     using (var context = new EventContainer())
     {
         Event updatedEvent = new Event
         {
             Id = id,
             StudentMatricId = matricId,
             Name            = name,
             Description     = description,
             Start           = start,
             End             = end,
             TimeCreated     = DateTime.Now,
             Capacity        = capacity,
             ViewAtLoginPage = viewAtLoginPage,
         };
         context.Events.Attach(updatedEvent);
         context.Entry(updatedEvent).State = EntityState.Modified;
         context.SaveChanges();
         return(updatedEvent);
     }
 }
Exemplo n.º 15
0
        public static SubEvent updateObj(SubEvent e)
        {
            e.Venue = DBLayer.DomainModels.VenueModel.getByID(e.VenueId);

            using (var context = new EventContainer())
            {
                context.Entry(e).State = EntityState.Modified;
                context.SaveChanges();

                return e;
            }
        }
Exemplo n.º 16
0
 public static Event update(int id, string matricId, string name, int venueId, DateTime start, DateTime end, int capacity, int budget = 0, string description = "", short viewAtLoginPage = 1)
 {
     using (var context = new EventContainer())
     {
         Event updatedEvent = new Event
         {
             Id = id,
             StudentMatricId = matricId,
             Name = name,
             Description = description,
             Start = start,
             End = end,
             TimeCreated = DateTime.Now,
             ViewAtLoginPage = viewAtLoginPage,
         };
         context.Events.Attach(updatedEvent);
         context.Entry(updatedEvent).State = EntityState.Modified;
         context.SaveChanges();
         return updatedEvent;
     }
 }