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(); } }
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(); } }
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(); } }
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; }