/// <summary> /// UpdateAttachment /// </summary> /// <param name="responseContext"></param> /// <param name="responseStatus"></param> /// <param name="userId"></param> /// <param name="newResponseStatus"></param> /// <returns></returns> public async Task <bool> UpdateAttachment(IResponseContext responseContext, int responseStatus, int userId = 0, int newResponseStatus = 0) { newResponseStatus = responseStatus; bool isSuccessful = false; bool deleteResponse = false; try { Uri rootFormCollectionUri = GetCollectionUri(responseContext.RootFormName); FormResponseResource formResponseResource = ReadRootResponseResource(responseContext); if (formResponseResource != null) { var formResponseProperties = formResponseResource.FormResponseProperties; //Is status is Saved and check if attachment is existed or not.If attachment is null and delete attachment if (newResponseStatus == RecordStatus.Saved) { Attachment attachment = ReadResponseAttachment(responseContext, AttachmentId); if (attachment != null) { deleteResponse = DeleteAttachment(attachment); } formResponseResource.CascadeThroughChildren(formResponseProperties, f => { if (f.RecStatus != RecordStatus.Deleted) { f.RecStatus = RecordStatus.Saved; } }); } if (newResponseStatus != formResponseProperties.RecStatus) { switch (newResponseStatus) { case RecordStatus.Saved: formResponseProperties.IsNewRecord = false; formResponseProperties.RecStatus = RecordStatus.Saved; var formResponseSave = await Client.UpsertDocumentAsync(rootFormCollectionUri, formResponseResource).ConfigureAwait(false); break; } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(isSuccessful); }
/// <summary> /// ToHierarchicalFormResponseDetail /// </summary> /// <param name="formResponseProperties"></param> /// <param name="formResponseResource"></param> /// <returns></returns> public static FormResponseDetail ToHierarchicalFormResponseDetail(this FormResponseProperties formResponseProperties, FormResponseResource formResponseResource) { FormResponseDetail formResponseDetail = formResponseProperties.ToFormResponseDetail(); List <FormResponseDetail> flattened = formResponseDetail.FlattenHierarchy(); formResponseResource.CascadeThroughChildren(formResponseProperties, frp => { var frd = frp.ToFormResponseDetail(); var parent = flattened.Where(f => f.ResponseId == frp.ParentResponseId).SingleOrDefault(); if (parent != null) { parent.ChildFormResponseDetailList.Add(frd); } else { throw new KeyNotFoundException(); } flattened.Add(frd); }); return(formResponseDetail); }