Beispiel #1
0
        /// <summary>
        /// Saves an entity.
        /// </summary>
        /// <param name="entity">The resource entity to save.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <returns>The changing result information.</returns>
        public override async Task <ChangingResultInfo> SaveAsync(ReceivedMailEntity entity, CancellationToken cancellationToken = default)
        {
            if (entity == null)
            {
                return(new ChangingResultInfo(ChangeErrorKinds.Argument, EntityNullTips));
            }
            if (string.IsNullOrWhiteSpace(UserId))
            {
                return(new ChangingResultInfo(ChangeErrorKinds.Unauthorized, LoginErrorTips));
            }
            if (string.IsNullOrWhiteSpace(entity.OwnerId) && entity.IsNew)
            {
                entity.OwnerId = UserId;
            }
            try
            {
                var result = await DataProvider.SaveAsync(entity, cancellationToken);

                if (ResourceEntityExtensions.IsSuccessful(result))
                {
                    return(new ChangingResultInfo <ReceivedMailEntity>(result, entity, result.ToString() + " received mail entity."));
                }
                return(result);
            }
            catch (Exception ex)
            {
                var err = ResourceEntityExtensions.TryCatch(ex);
                if (err != null)
                {
                    return(err);
                }
                throw;
            }
        }
Beispiel #2
0
 private static Task <ChangeMethods> SaveAsync <T>(IList <T> col, T entity, CancellationToken cancellationToken = default) where T : BaseResourceEntity
 {
     if (col is null || entity is null)
     {
         return(Task.FromResult(ChangeMethods.Invalid));
     }
     return(ResourceEntityExtensions.SaveAsync(entity, col.Add, ele =>
     {
         var removing = col.FirstOrDefault(ele => ele.Id == entity.Id);
         if (removing != null)
         {
             col.Remove(removing);
         }
         col.Add(entity);
     }, cancellationToken));
 }
Beispiel #3
0
        /// <summary>
        /// Updates a specific entity.
        /// </summary>
        /// <param name="id">The resource entity identifier.</param>
        /// <param name="state">The state to change.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <returns>The changing result information.</returns>
        public override async Task <ChangingResultInfo> UpdateUserGroupActivityAsync(string id, ResourceEntityStates state, CancellationToken cancellationToken = default)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(new ChangingResultInfo(ChangeErrorKinds.Argument, "Requires an entity identifier."));
            }
            if (string.IsNullOrWhiteSpace(UserId))
            {
                return(new ChangingResultInfo(ChangeErrorKinds.Unauthorized, LoginErrorTips));
            }
            var entity = await DataProvider.GetUserGroupActivityAsync(id, cancellationToken);

            if (entity == null)
            {
                return(new ChangingResultInfo(ChangeErrorKinds.NotFound, "The entity does not exist."));
            }
            try
            {
                var result = await DataProvider.SaveAsync(entity, cancellationToken);

                if (ResourceEntityExtensions.IsSuccessful(result))
                {
                    return(new ChangingResultInfo <UserGroupActivityEntity>(result, entity, result.ToString() + " user group activity entity."));
                }
                return(result);
            }
            catch (Exception ex)
            {
                var err = ResourceEntityExtensions.TryCatch(ex);
                if (err != null)
                {
                    return(err);
                }
                throw;
            }
        }