Esempio n. 1
0
        public async Task <Models.Label> GetLabelAsync(string id, EntityHeader org, EntityHeader user)
        {
            var model = await _repo.GetLabelAsync(id);

            await AuthorizeAsync(model, AuthorizeResult.AuthorizeActions.Read, user, org);

            return(model);
        }
Esempio n. 2
0
        public async Task <InvokeResult> AddLabelForSampleAsync(Sample sample, string labelId, EntityHeader org, EntityHeader user)
        {
            var labelDetails = await _labelRepo.GetLabelAsync(labelId);

            var labels = await _labelSampleRepo.GetLabelsForSampleAsync(sample.RowKey);

            if (labels.Where(lbl => lbl.LabelId == labelId).Any())
            {
                return(InvokeResult.FromError("Label already attached."));
            }

            var label = new SampleLabel()
            {
                RowKey                = $"{sample.RowKey}-{labelId}",
                PartitionKey          = $"{labelId}-{sample.ContentType.Replace("/","-")}",
                SampleId              = sample.RowKey,
                FileName              = sample.FileName,
                ContentSize           = sample.ContentSize,
                ContentType           = sample.ContentType,
                Name                  = sample.Name,
                LabelId               = labelId,
                Label                 = labelDetails.Key,
                CreatedById           = user.Id,
                CreationDate          = DateTime.UtcNow.ToJSONString(),
                OwnerOrganizationId   = org.Id,
                OwnerOrganizationName = org.Text,
            };

            await _sampleLabelRepo.AddSampleLabelAsync(label);

            var labelSample = new LabelSample()
            {
                RowKey       = $"{labelId}-{sample.RowKey}",
                PartitionKey = sample.RowKey,
                Label        = labelDetails.Key,
                LabelId      = labelId,
            };

            await _labelSampleRepo.AddLabelSampleAsync(labelSample);

            return(InvokeResult.Success);
        }