/// <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; } }
/// <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; } }