public void SaveEarnedBadges(IQueryable<BadgeAwardDTO> badges)
 {
     using (var ctx = new Entities())
     {
         ctx.Database.Connection.Open();
         var badgeAwards = new List<BadgeAward>();
         foreach (var badge in badges)
         {
             var saveBadge = LoadData(badge);
             ctx.BadgeAwards.Add(saveBadge);
             badgeAwards.Add(saveBadge);
         }
         ctx.SaveChanges();
         foreach (var badgeAward in badgeAwards)
         {
             var queueItem = new QueueItem
             {
                 BadgeAwardId = badgeAward.BadgeAwardId,
                 QueueItemCreated = badgeAward.AwardDate
             };
             ctx.QueueItems.Add(queueItem);
         }
         ctx.SaveChanges();
     }
 }
Esempio n. 2
0
        public QueueItemDTO Update(QueueItemDTO item)
        {
            using (Entities context = new Entities())
            {
                QueueItem itemToUpdate = new QueueItem                 
                {
                    QueueItemId = item.QueueItemId,
                    BadgeAwardId = item.BadgeAwardId,                    
                    QueueItemCreated = item.QueueItemCreated
                };

                context.QueueItems.Attach(itemToUpdate);
                context.Entry(itemToUpdate).State = System.Data.Entity.EntityState.Modified;
                
                context.SaveChanges();

                return Get(item.QueueItemId);
            }
        }