Example #1
0
 /// <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(Communication newdata)
 {
     int cnt = 0;
     if (AddressInfo != newdata.AddressInfo)
     {
         AddressInfo = newdata.AddressInfo;
         IsAddressInfoModified = true;
         cnt++;
     }
     if (Comment != newdata.Comment)
     {
         Comment = newdata.Comment;
         IsCommentModified = true;
         cnt++;
     }
     IsEntityChanged = cnt > 0;
 }
Example #2
0
 /// <summary>
 /// Internal use
 /// </summary>
 public Communication ShallowCopy(bool allData = false)
 {
     Communication e = new Communication();
     e.IsInitializing = true;
     e.ID = ID;
     e.AddressInfo = AddressInfo;
     e.ApplicationID = ApplicationID;
     e.TypeID = TypeID;
     e.UserID = UserID;
     if (allData)
     {
         e.Comment = Comment;
     }
     e.DistinctString = GetDistinctString(true);
     e.IsPersisted = true;
     e.IsEntityChanged = false;
     e.IsInitializing = false;
     return e;
 }
Example #3
0
 /// <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(Communication from, Communication to)
 {
     if (to.IsPersisted)
     {
         if (from.IsAddressInfoModified && !to.IsAddressInfoModified)
         {
             to.AddressInfo = from.AddressInfo;
             to.IsAddressInfoModified = true;
         }
         if (from.IsCommentModified && !to.IsCommentModified)
         {
             to.Comment = from.Comment;
             to.IsCommentModified = true;
         }
     }
     else
     {
         to.IsPersisted = from.IsPersisted;
         to.ID = from.ID;
         to.AddressInfo = from.AddressInfo;
         to.IsAddressInfoModified = from.IsAddressInfoModified;
         to.Comment = from.Comment;
         to.IsCommentModified = from.IsCommentModified;
         to.ApplicationID = from.ApplicationID;
         to.TypeID = from.TypeID;
         to.UserID = from.UserID;
     }
 }
Example #4
0
 /// <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(Communication other)
 {
     if (other == null)
         return false;
     else
         return ID == other.ID;
 }              
Example #5
0
 /// <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(Communication other)
 {
     if (other == null)
         return false;
     if (ID != other.ID)
         return false;
     return true;
 }              
 /// <summary>
 /// Internal use
 /// </summary>
 public Communication ShallowCopy(bool allData = false, bool preserveState = false)
 {
     Communication e = new Communication();
     e.StartAutoUpdating = false;
     e.ID = ID;
     e.AddressInfo = AddressInfo;
     if (preserveState)
         e.IsAddressInfoModified = IsAddressInfoModified;
     else
         e.IsAddressInfoModified = false;
     e.ApplicationID = ApplicationID;
     e.TypeID = TypeID;
     e.UserID = UserID;
     if (allData)
     {
         e.Comment = Comment;
         if (preserveState)
             e.IsCommentModified = IsCommentModified;
         else
             e.IsCommentModified = false;
     }
     e.DistinctString = GetDistinctString(true);
     e.IsPersisted = IsPersisted;
     if (preserveState)
         e.IsEntityChanged = IsEntityChanged;
     else
         e.IsEntityChanged = false;
     e.StartAutoUpdating = true;
     return e;
 }
 public static async Task<dynamic> AddChannel(string id, int typeId, string address, string comment)
 {
     CommunicationServiceProxy csvc = new CommunicationServiceProxy();
     Communication c = new Communication();
     c.ID = Guid.NewGuid().ToString();
     c.TypeID = typeId;
     c.UserID = id;
     c.ApplicationID = ApplicationContext.App.ID;
     c.AddressInfo = address;
     c.Comment = comment;
     var result = await csvc.AddOrUpdateEntitiesAsync(Cntx, new CommunicationSet(), new Communication[] { c });
     if ((result.ChangedEntities[0].OpStatus & (int)EntityOpStatus.Added) > 0)
     {
         c = result.ChangedEntities[0].UpdatedItem;
         c.CommunicationTypeRef = await csvc.MaterializeCommunicationTypeRefAsync(Cntx, c);
         var dc = new { id = c.ID, label = c.DistinctString, addr = c.AddressInfo, comment = c.Comment, typeId = c.CommunicationTypeRef.TypeName };
         return new { ok = true, msg = "", data = dc };
     }
     else
         return new { ok = false, msg = ResourceUtils.GetString("954122aa46fdc842a03ed8b89acdd125", "Add failed!") };
 }