/// <summary> /// Merge changes inside entity <paramref name="from" /> to the entity <paramref name="to" />. Any changes in <paramref name="from" /> that is not changed in <paramref name="to" /> is updated inside <paramref name="to" />. /// </summary> /// <param name="from">The "old" entity acting as merging source.</param> /// <param name="to">The "new" entity which inherits changes made in <paramref name="from" />.</param> /// <returns> /// </returns> public static void MergeChanges(ShortMessageAudience from, ShortMessageAudience to) { if (to.IsPersisted) { if (from.IsVoteCountModified && !to.IsVoteCountModified) { to.VoteCount = from.VoteCount; to.IsVoteCountModified = true; } if (from.IsLockItModified && !to.IsLockItModified) { to.LockIt = from.LockIt; to.IsLockItModified = true; } } else { to.IsPersisted = from.IsPersisted; to.MsgID = from.MsgID; to.UserID = from.UserID; to.VoteCount = from.VoteCount; to.IsVoteCountModified = from.IsVoteCountModified; to.LockIt = from.LockIt; to.IsLockItModified = from.IsLockItModified; } }
/// <summary> /// Whether or not the present entity is identitical to <paramref name="other" />, in the sense that they have the same (set of) intrinsic identifiers. /// </summary> /// <param name="other">The entity to be compared to.</param> /// <returns> /// The result of comparison. /// </returns> public bool IsEntityTheSame(ShortMessageAudience other) { if (other == null) { return(false); } else { return(MsgID == other.MsgID && UserID == other.UserID); } }
/// <summary> /// Whether or not the present entity is identitical to <paramref name="other" />, in the sense that they have the same (set of) primary key(s). /// </summary> /// <param name="other">The entity to be compared to.</param> /// <returns> /// The result of comparison. /// </returns> public bool IsEntityIdentical(ShortMessageAudience other) { if (other == null) { return(false); } if (MsgID != other.MsgID) { return(false); } if (UserID != other.UserID) { return(false); } return(true); }
/// <summary> /// Update changes to the current entity compared to an input <paramref name="newdata" /> and set the entity to a proper state for updating. /// </summary> /// <param name="newdata">The "new" entity acting as the source of the changes, if any.</param> /// <returns> /// </returns> public void UpdateChanges(ShortMessageAudience newdata) { int cnt = 0; if (VoteCount != newdata.VoteCount) { VoteCount = newdata.VoteCount; IsVoteCountModified = true; cnt++; } if (LockIt != newdata.LockIt) { LockIt = newdata.LockIt; IsLockItModified = true; cnt++; } IsEntityChanged = cnt > 0; }
/// <summary> /// Internal use /// </summary> public ShortMessageAudience ShallowCopy(bool allData = false, bool preserveState = false, bool checkLoadState = false) { ShortMessageAudience e = new ShortMessageAudience(); e.StartAutoUpdating = false; e.MsgID = MsgID; e.UserID = UserID; e.VoteCount = VoteCount; if (preserveState) { e.IsVoteCountModified = IsVoteCountModified; } else { e.IsVoteCountModified = false; } e.LockIt = LockIt; if (preserveState) { e.IsLockItModified = IsLockItModified; } else { e.IsLockItModified = false; } e.DistinctString = GetDistinctString(true); e.IsPersisted = IsPersisted; if (preserveState) { e.IsEntityChanged = IsEntityChanged; } else { e.IsEntityChanged = false; } e.StartAutoUpdating = true; return(e); }
/// <summary> /// Update changes to the current entity compared to an input <paramref name="newdata" /> and set the entity to a proper state for updating. /// </summary> /// <param name="newdata">The "new" entity acting as the source of the changes, if any.</param> /// <returns> /// </returns> public void UpdateChanges(ShortMessageAudience newdata) { int cnt = 0; if (VoteCount != newdata.VoteCount) { VoteCount = newdata.VoteCount; IsVoteCountModified = true; cnt++; } if (LockIt != newdata.LockIt) { LockIt = newdata.LockIt; IsLockItModified = true; cnt++; } IsEntityChanged = cnt > 0; }
/// <summary> /// Internal use /// </summary> public ShortMessageAudience ShallowCopy(bool allData = false, bool preserveState = false, bool checkLoadState = false) { ShortMessageAudience e = new ShortMessageAudience(); e.StartAutoUpdating = false; e.MsgID = MsgID; e.UserID = UserID; e.VoteCount = VoteCount; if (preserveState) e.IsVoteCountModified = IsVoteCountModified; else e.IsVoteCountModified = false; e.LockIt = LockIt; if (preserveState) e.IsLockItModified = IsLockItModified; else e.IsLockItModified = false; e.DistinctString = GetDistinctString(true); e.IsPersisted = IsPersisted; if (preserveState) e.IsEntityChanged = IsEntityChanged; else e.IsEntityChanged = false; e.StartAutoUpdating = true; return e; }
/// <summary> /// Merge changes inside entity <paramref name="from" /> to the entity <paramref name="to" />. Any changes in <paramref name="from" /> that is not changed in <paramref name="to" /> is updated inside <paramref name="to" />. /// </summary> /// <param name="from">The "old" entity acting as merging source.</param> /// <param name="to">The "new" entity which inherits changes made in <paramref name="from" />.</param> /// <returns> /// </returns> public static void MergeChanges(ShortMessageAudience from, ShortMessageAudience to) { if (to.IsPersisted) { if (from.IsVoteCountModified && !to.IsVoteCountModified) { to.VoteCount = from.VoteCount; to.IsVoteCountModified = true; } if (from.IsLockItModified && !to.IsLockItModified) { to.LockIt = from.LockIt; to.IsLockItModified = true; } } else { to.IsPersisted = from.IsPersisted; to.MsgID = from.MsgID; to.UserID = from.UserID; to.VoteCount = from.VoteCount; to.IsVoteCountModified = from.IsVoteCountModified; to.LockIt = from.LockIt; to.IsLockItModified = from.IsLockItModified; } }
/// <summary> /// Whether or not the present entity is identitical to <paramref name="other" />, in the sense that they have the same (set of) intrinsic identifiers. /// </summary> /// <param name="other">The entity to be compared to.</param> /// <returns> /// The result of comparison. /// </returns> public bool IsEntityTheSame(ShortMessageAudience other) { if (other == null) return false; else return MsgID == other.MsgID && UserID == other.UserID; }
/// <summary> /// Whether or not the present entity is identitical to <paramref name="other" />, in the sense that they have the same (set of) primary key(s). /// </summary> /// <param name="other">The entity to be compared to.</param> /// <returns> /// The result of comparison. /// </returns> public bool IsEntityIdentical(ShortMessageAudience other) { if (other == null) return false; if (MsgID != other.MsgID) return false; if (UserID != other.UserID) return false; return true; }
public static async Task<int> VoteOnMessage(string msgId, string userId, int del) { var cntx = Cntx; cntx.DirectDataAccess = true; ShortMessageAudienceServiceProxy audsvc = new ShortMessageAudienceServiceProxy(); var aud = await audsvc.LoadEntityByKeyAsync(cntx, msgId, userId); if (aud == null) { aud = new ShortMessageAudience { MsgID = msgId, UserID = userId, VoteCount = del }; } else aud.VoteCount += del; await audsvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageAudienceSet(), new ShortMessageAudience[] { aud }); return aud.VoteCount; }
public static async Task<ShotMessageNotice> UpdateUserMessage(string noticeHubId, string chatHubId, string userId, string groupId, string msgId, string message) { var cntx = Cntx; UserGroupServiceProxy gsvc = new UserGroupServiceProxy(); var g = await gsvc.LoadEntityByKeyAsync(cntx, groupId); ShortMessageServiceProxy msvc = new ShortMessageServiceProxy(); var msg = await msvc.LoadEntityByKeyAsync(cntx, msgId); if (msg == null || msg.FromID != userId) return null; if (msg.MsgText == message) return null; var now = DateTime.UtcNow; msg.MsgTitle = GetLeadText(message); msg.MsgText = message; msg.LastModified = now; await msvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg }); UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); msg.User_FromID = u; UserGroupMemberServiceProxy gmsvc = new UserGroupMemberServiceProxy(); var cond = new UserGroupMemberSetConstraints { UserGroupIDWrap = new ForeignKeyData<string> { KeyValue = groupId } }; var qexpr = new QueryExpresion(); qexpr.OrderTks = new List<QToken>(new QToken[] { new QToken { TkName = "UserID" } }); qexpr.FilterTks = new List<QToken>(new QToken[] { new QToken { TkName = "SubscribedTo is not null && SubscribedTo == true" } }); var gmbs = await gmsvc.ConstraintQueryAsync(cntx, new UserGroupMemberSet(), cond, qexpr); List<MemberNotification> notices = new List<MemberNotification>(); List<MemberCallback> noteCbks = new List<MemberCallback>(); MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy(); string noticeMsg = "Group message by " + u.Username + " updated in " + g.DistinctString; MemberNotificationTypeServiceProxy ntsvc = new MemberNotificationTypeServiceProxy(); var ntype = await ntsvc.LoadEntityByKeyAsync(cntx, ApplicationContext.NewMessageNoticeTypeId); foreach (var m in gmbs) { if (m.ActivityNotification.HasValue && m.ActivityNotification.Value) { var cb = await mcbsvc.LoadEntityByKeyAsync(cntx, groupId, noticeHubId, AppId, m.UserID); if (cb.ConnectionID != null && !cb.IsDisconnected) { cb.UserAppMemberRef = await mcbsvc.MaterializeUserAppMemberRefAsync(cntx, cb); noteCbks.Add(cb); } } notices.Add(new MemberNotification { ID = Guid.NewGuid().ToString(), Title = noticeMsg, CreatedDate = now, PriorityLevel = 0, ReadCount = 0, ApplicationID = AppId, TypeID = ApplicationContext.NewMessageNoticeTypeId, UserID = userId }); } var peers = await ListConnectIds(chatHubId, groupId); List<ShortMessageAudience> laud = new List<ShortMessageAudience>(); foreach (var peer in peers) { if (peer.UserID != userId) { var a = new ShortMessageAudience { MsgID = msg.ID, UserID = peer.UserID, VoteCount = 0 }; laud.Add(a); } } if (laud.Count > 0) { ShortMessageAudienceServiceProxy audsvc = new ShortMessageAudienceServiceProxy(); await audsvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageAudienceSet(), laud.ToArray()); } if (notices.Count > 0) { MemberNotificationServiceProxy nsvc = new MemberNotificationServiceProxy(); await nsvc.AddOrUpdateEntitiesAsync(cntx, new MemberNotificationSet(), notices.ToArray()); } return new ShotMessageNotice { msg = GetJsonMessage(msg, userId, g, false), brief = noticeMsg, categ = ntype, peers = peers, callbacks = noteCbks }; }