Ejemplo n.º 1
0
        public void AddAttachmentToOwnAvatar(SInAttachment attachment, int callerId)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var avatarOwner = ctx.Person.FirstOrDefault(p => p.Id == callerId);
                if (avatarOwner == null)
                    return;

                DAL.Helper.AddAttachment(ctx, argPoint: null,
                                        discussion: null, personWithAvatar: avatarOwner,
                                        attachment: attachment,
                                        callerId: callerId);

                ctx.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public void AddAttachmentToPoint(int pointId, SInAttachment attachment, int callerId)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var point = ctx.ArgPoint.FirstOrDefault(ap => ap.Id == pointId);
                if (point == null)
                    return;

                DAL.Helper.AddAttachment(ctx, argPoint:point, 
                                        discussion:null, personWithAvatar:null, 
                                        attachment:attachment,
                                        callerId:callerId);

                ctx.SaveChanges();
            }            
        }
Ejemplo n.º 3
0
        public void AddAttachmentToDiscussion(int discussionId, SInAttachment attachment, int callerId)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var discussion = ctx.Discussion.FirstOrDefault(d => d.Id == discussionId);
                if (discussion == null)
                    return;

                DAL.Helper.AddAttachment(ctx, argPoint: null,
                                        discussion: discussion, personWithAvatar: null,
                                        attachment: attachment,
                                        callerId: callerId);

                ctx.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        public static void AddAttachment(DiscCtx ctx,
                                         [CanBeNull]ArgPoint argPoint, [CanBeNull]Discussion discussion, [CanBeNull]Person personWithAvatar,
                                         SInAttachment attachment,
                                         int callerId)
        {
            var caller = ctx.Person.FirstOrDefault(p => p.Id == callerId);
            if (caller == null)
                return;

            Attachment lastAttachment = null;
            if (argPoint != null)
                lastAttachment = argPoint.Attachment.LastOrDefault();
            else if (discussion != null)
                lastAttachment = discussion.Attachment.LastOrDefault();
            else if (personWithAvatar != null)
                lastAttachment = personWithAvatar.Attachment.LastOrDefault();
                                        
            var dbMediaData = new MediaData {Data = attachment.MediaData};
                        
            var dbAttachent = attachment.ToDbEntity(ctx);
            dbAttachent.MediaData = dbMediaData;
            dbAttachent.OrderNumber = lastAttachment != null ? lastAttachment.OrderNumber + 1 : 1;

            //switch 
            {
                dbAttachent.Discussion = discussion;
                dbAttachent.PersonWithAvatar = personWithAvatar;
                dbAttachent.ArgPoint = argPoint;
            }

            dbAttachent.Person = caller;           
        }