Пример #1
0
        public async Task <IActionResult> Delete(Guid instanceId, Guid dataId, int instanceOwnerId)
        {
            // check if instance id exist and user is allowed to change the instance data
            Instance instance = await _instanceRepository.GetOneAsync(instanceId, instanceOwnerId);

            if (instance == null)
            {
                return(NotFound("Provided instanceId is unknown to storage service"));
            }

            string dataIdString = dataId.ToString();

            if (instance.Data.Exists(m => m.Id == dataIdString))
            {
                string storageFileName = DataFileName(instance.ApplicationId, instanceId.ToString(), dataId.ToString());

                bool result = await _dataRepository.DeleteDataInStorage(storageFileName);

                if (result)
                {
                    // Update instance record
                    Data data = instance.Data.Find(m => m.Id == dataIdString);
                    instance.Data.Remove(data);
                    Instance storedInstance = await _instanceRepository.UpdateInstanceInCollectionAsync(instanceId, instance);

                    return(Ok(storedInstance));
                }
            }

            return(BadRequest());
        }
Пример #2
0
        public async Task <ActionResult> Get(Guid instanceId, int instanceOwnerId)
        {
            var result = await _instanceRepository.GetOneAsync(instanceId, instanceOwnerId);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
Пример #3
0
        public async Task <ActionResult> Get(Guid instanceId, int instanceOwnerId)
        {
            Stopwatch watch = Stopwatch.StartNew();

            var result = await _instanceRepository.GetOneAsync(instanceId, instanceOwnerId);

            if (result == null)
            {
                return(NotFound("Did not find an instance with instanceId=" + instanceId));
            }

            watch.Stop();
            logger.Information("get {instanceid} for {instanceOwner} took {time}ms.", instanceId, instanceOwnerId, watch.ElapsedMilliseconds);

            return(Ok(result));
        }
Пример #4
0
        public async Task <IActionResult> Get(int instanceOwnerId, Guid instanceId, string formId, Guid dataId)
        {
            if (instanceOwnerId == 0 || instanceId == null || string.IsNullOrEmpty(formId) || dataId == null)
            {
                return(BadRequest("Missing parameter values: instanceOwnerId, instanceId, formId or dataId cannot be null"));
            }

            // check if instance id exist and user is allowed to change the instance data
            Instance instance = await _instanceRepository.GetOneAsync(instanceId, instanceOwnerId);

            if (instance == null)
            {
                return(NotFound("Provided instanceId is unknown to platform storage service"));
            }

            string storageFileName = instance.ApplicationId + "/" + instanceId + "/data/" + formId + "/" + dataId;

            // check if dataId exists in instance
            if (instance.Data.ContainsKey(formId))
            {
                Dictionary <string, Data> formData = instance.Data[formId];
                if (formData.ContainsKey(dataId.ToString()))
                {
                    Data data = formData[dataId.ToString()];

                    if (string.Equals(data.StorageUrl, storageFileName))
                    {
                        Stream dataStream = await _dataRepository.GetDataInStorage(storageFileName);

                        if (dataStream == null)
                        {
                            return(NotFound());
                        }

                        return(File(dataStream, data.ContentType, data.FileName));
                    }
                }
            }

            return(NotFound("Unable to find requested data item"));
        }
Пример #5
0
        public async Task <IActionResult> Delete(Guid instanceId, string formId, Guid dataId, int instanceOwnerId)
        {
            // check if instance id exist and user is allowed to change the instance data
            Instance instance = await _instanceRepository.GetOneAsync(instanceId, instanceOwnerId);

            if (instance == null)
            {
                return(NotFound("Provided instanceId is unknown to storage service"));
            }

            string storageFileName = DataFileName(instance.ApplicationId, instanceId.ToString(), formId, dataId.ToString());

            bool result = await _dataRepository.DeleteDataInStorage(storageFileName);

            if (result)
            {
                return(Ok());
            }

            return(BadRequest());
        }