Esempio n. 1
0
        public void RemoveComment(int commentId)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var dbComment = ctx.Comment.FirstOrDefault(c => c.Id == commentId);
                if (dbComment == null)
                    return;

                ctx.DeleteObject(dbComment);
                ctx.SaveChanges();
            }
        }
Esempio n. 2
0
 public static ScreenshotResponse Read(Dictionary<byte, object> par)
 {
     var res = new ScreenshotResponse();
     res.screenshots = new Dictionary<int, byte[]>();
     using (var ctx = new DiscCtx(Discussions.ConfigManager.ConnStr))
     {
         var shapeIds = (int[]) par[(byte) DiscussionParamKey.ArrayOfInts];
         for (int i = 0; i < shapeIds.Length; i++)
         {
             int mediaId = (int) par[(byte) i];
             var mediaEntity = ctx.MediaDataSet.Single(m => m.Id == mediaId);
             res.screenshots.Add(shapeIds[i], mediaEntity.Data);
             ctx.DeleteObject(mediaEntity); 
         }
         ctx.SaveChanges(); //deleted entities 
         return res;
     }
 }
        public void Dispose()
        {
            if (_cachedEntity != null && _mediaStream != null)
            {
                // Get the new entity from the Entity Framework object state manager.
                ObjectStateEntry entry = this.context.ObjectStateManager.GetObjectStateEntry(_cachedEntity);

                if (entry.State == EntityState.Unchanged)
                {
                    {
                        var ctx = new DiscCtx(ConfigManager.ConnStr);
                        ctx.Attach(_cachedEntity);
                        _cachedEntity.MediaData.Data = _mediaStream.ToArray();
                        ctx.SaveChanges();
                    }
                }
                else
                {
                    // A problem must have occurred when saving the entity to the database, 
                    // so we should delete the entity
                    var mediaData = _cachedEntity.MediaData;
                    _cachedEntity.MediaData = null;
                    var ctx = new DiscCtx(ConfigManager.ConnStr);
                    if (mediaData != null)
                    {
                        ctx.Attach(mediaData);
                        ctx.DeleteObject(mediaData);
                    }
                    ctx.Attach(_cachedEntity);
                    ctx.DeleteObject(_cachedEntity);

                    throw new DataServiceException("An error occurred. The media resource could not be saved.");
                }
            }
        }
Esempio n. 4
0
        public void RemoveAttachment(int attachmentId)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var attachment = ctx.Attachment.FirstOrDefault(at => at.Id == attachmentId);
                if (attachment == null)
                    return;
                
                if (attachment.MediaData != null)                
                    ctx.DeleteObject(attachment.MediaData);                 
                ctx.DeleteObject(attachment);

                ctx.SaveChanges();
            }
        }
Esempio n. 5
0
        public static void DeleteArgPoint(DiscCtx ctx, ArgPoint p)
        {
            p.Topic = null;
            p.Person = null;
            p.Comment.Clear();
            p.Attachment.Clear();
            p.Description = null;

            try
            {
                ctx.DeleteObject(p);
            }
            catch (Exception)
            {
                //if person doesn't exist, ignore 
            }
        }