Exemple #1
0
        /// <summary>
        /// Updates the specified OutlookItem using PATCH.
        /// </summary>
        /// <param name="outlookItemToUpdate">The OutlookItem to update.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <exception cref="ClientException">Thrown when an object returned in a response is used for updating an object in Microsoft Graph.</exception>
        /// <returns>The updated OutlookItem.</returns>
        public async System.Threading.Tasks.Task <OutlookItem> UpdateAsync(OutlookItem outlookItemToUpdate, CancellationToken cancellationToken)
        {
            if (outlookItemToUpdate.AdditionalData != null)
            {
                if (outlookItemToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||
                    outlookItemToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))
                {
                    throw new ClientException(
                              new Error
                    {
                        Code    = GeneratedErrorConstants.Codes.NotAllowed,
                        Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, outlookItemToUpdate.GetType().Name)
                    });
                }
            }
            if (outlookItemToUpdate.AdditionalData != null)
            {
                if (outlookItemToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||
                    outlookItemToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))
                {
                    throw new ClientException(
                              new Error
                    {
                        Code    = GeneratedErrorConstants.Codes.NotAllowed,
                        Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, outlookItemToUpdate.GetType().Name)
                    });
                }
            }
            this.ContentType = "application/json";
            this.Method      = "PATCH";
            var updatedEntity = await this.SendAsync <OutlookItem>(outlookItemToUpdate, cancellationToken).ConfigureAwait(false);

            this.InitializeCollectionProperties(updatedEntity);
            return(updatedEntity);
        }
        /// <summary>
        /// Creates the specified OutlookItem using PUT.
        /// </summary>
        /// <param name="outlookItemToCreate">The OutlookItem to create.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <returns>The created OutlookItem.</returns>
        public async Task <OutlookItem> CreateAsync(OutlookItem outlookItemToCreate, CancellationToken cancellationToken)
        {
            this.ContentType = "application/json";
            this.Method      = "PUT";
            var newEntity = await this.SendAsync <OutlookItem>(outlookItemToCreate, cancellationToken).ConfigureAwait(false);

            this.InitializeCollectionProperties(newEntity);
            return(newEntity);
        }
        /// <summary>
        /// Updates the specified OutlookItem using PATCH.
        /// </summary>
        /// <param name="outlookItemToUpdate">The OutlookItem to update.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <returns>The updated OutlookItem.</returns>
        public async System.Threading.Tasks.Task <OutlookItem> UpdateAsync(OutlookItem outlookItemToUpdate, CancellationToken cancellationToken)
        {
            this.ContentType = "application/json";
            this.Method      = "PATCH";
            var updatedEntity = await this.SendAsync <OutlookItem>(outlookItemToUpdate, cancellationToken).ConfigureAwait(false);

            this.InitializeCollectionProperties(updatedEntity);
            return(updatedEntity);
        }
Exemple #4
0
        /// <summary>
        /// Save item on the server.
        /// </summary>
        /// <param name="parentFolderId">Parent folder id.</param>
        /// <returns></returns>
        public void Save(FolderId parentFolderId)
        {
            this.PreValidateSave();
            ArgumentValidator.ThrowIfNull(parentFolderId, nameof(parentFolderId));

            OutlookItem outlookItem = this.Service.CreateItem(
                this,
                parentFolderId);

            this.propertyBag = outlookItem.propertyBag;
            this.MailboxId   = outlookItem.MailboxId;
        }
Exemple #5
0
        /// <summary>
        /// Update outlook item.
        /// </summary>
        public void Update()
        {
            if (this.IsNew)
            {
                throw new ArgumentException("Cannot perform update on newly created item. Sync item from server and try again.");
            }

            if (this.propertyBag.GetChangedProperties().Count == 0)
            {
                throw new ArgumentException("No changed properties detected.");
            }

            OutlookItem outlookItem = this.Service.UpdateItem(this);

            this.propertyBag = outlookItem.propertyBag;
            this.MailboxId   = outlookItem.MailboxId;
        }
 /// <summary>
 /// Creates the specified OutlookItem using PUT.
 /// </summary>
 /// <param name="outlookItemToCreate">The OutlookItem to create.</param>
 /// <returns>The created OutlookItem.</returns>
 public Task <OutlookItem> CreateAsync(OutlookItem outlookItemToCreate)
 {
     return(this.CreateAsync(outlookItemToCreate, CancellationToken.None));
 }
 /// <summary>
 /// Initializes any collection properties after deserialization, like next requests for paging.
 /// </summary>
 /// <param name="outlookItemToInitialize">The <see cref="OutlookItem"/> with the collection properties to initialize.</param>
 private void InitializeCollectionProperties(OutlookItem outlookItemToInitialize)
 {
 }
Exemple #8
0
 /// <summary>
 /// Creates the specified OutlookItem using POST.
 /// </summary>
 /// <param name="outlookItemToCreate">The OutlookItem to create.</param>
 /// <returns>The created OutlookItem.</returns>
 public System.Threading.Tasks.Task <OutlookItem> CreateAsync(OutlookItem outlookItemToCreate)
 {
     return(this.CreateAsync(outlookItemToCreate, CancellationToken.None));
 }