/// <summary> /// Updates an existing COR from a PUT when a "If-Match" header is included using the corresponding etag. /// </summary> /// <param name="propertiesAndHeaders"></param> /// <param name="response"></param> private async Task UpdateCalendarObjectResource(Dictionary <string, string> propertiesAndHeaders, HttpResponse response) { #region Extracting Properties string url; propertiesAndHeaders.TryGetValue("url", out url); string body; propertiesAndHeaders.TryGetValue("body", out body); //var headers = response.GetTypedHeaders(); #endregion //var iCal = new VCalendar(body); //Fill the resource //var resource = FillResource(propertiesAndHeaders, iCal, response); var etag = $"\"{Guid.NewGuid()}\""; response.Headers["etag"] = etag; //headers.ETag = new EntityTagHeaderValue(etag, false); var errorStack = new Stack <string>(); //updating the etag await _resourceRespository.CreateOrModifyProperty(url, "getetag", _namespacesSimple["D"], $"<D:getetag {_namespaces["D"]}>{etag}</D:getetag>", errorStack, true); //updating the ctag await _collectionRespository.CreateOrModifyProperty( url?.Remove(url.LastIndexOf("/", StringComparison.Ordinal) + 1), "getctag", _namespacesSimple["S"], $@"<S:getctag {_namespaces["S"]} >{Guid.NewGuid()}</S:getctag>", errorStack, true); //updating the lastmodified await _resourceRespository.CreateOrModifyProperty(url, "getlastmodified", _namespacesSimple["D"], $"<D:getlastmodified {_namespaces["D"]}>{DateTime.Now}</D:getlastmodified>", errorStack, true); //Removing old File StorageManagement.DeleteCalendarObjectResource(url); //Adding New File await StorageManagement.AddCalendarObjectResourceFile(url, body); await _resourceRespository.CreateOrModifyProperty(url, "getcontentlength", "DAV:", $"<D:getcontentlength {_namespaces["D"]}>{StorageManagement.GetFileSize(url)}</D:getcontentlength>", errorStack, true); //the response for this methos is NO CONTENT response.StatusCode = (int)HttpStatusCode.NoContent; //Adding to the dataBase await _resourceRespository.SaveChangeAsync(); }
/// <summary> /// Creates a new COR from a PUT when a "If-Non-Match" header is included /// </summary> /// <param name="propertiesAndHeaders"></param> /// <param name="response"></param> /// <param></param> private async Task CreateCalendarObjectResource(Dictionary <string, string> propertiesAndHeaders, HttpResponse response) { #region Extracting Properties string url; propertiesAndHeaders.TryGetValue("url", out url); string body; propertiesAndHeaders.TryGetValue("body", out body); response.GetTypedHeaders(); #endregion var iCal = new VCalendar(body); //filling the resource var resource = await FillResource(propertiesAndHeaders, iCal, response); //adding the resource to the db var collection = _collectionRespository.Get(url?.Remove(url.LastIndexOf("/", StringComparison.Ordinal) + 1)); collection.CalendarResources.Add(resource); //adding the file await StorageManagement.AddCalendarObjectResourceFile(url, body); response.StatusCode = (int)HttpStatusCode.Created; //setting the content lenght property. var errorStack = new Stack <string>(); await _resourceRespository.CreateOrModifyProperty(resource.Href, "getcontentlength", "DAV:", $"<D:getcontentlength {_namespaces["D"]}>{StorageManagement.GetFileSize(url)}</D:getcontentlength>", errorStack, true); await _collectionRespository.SaveChangeAsync(); }