Esempio n. 1
0
        public async Task <int> CreateAsync(int datasetId, RecordCreation recordCreation)
        {
            var userId = await GetUserIdAsync();

            var entity = _mapper.Create(recordCreation);

            await InvokeGuard(() => _guard.AgainstInvalidRecordCreationAsync(userId, datasetId, recordCreation));

            await _repository.AddRecordAsync(datasetId, entity);

            await _unitOfWork.SaveChangesAsync();

            return(entity.Id);
        }
Esempio n. 2
0
        public async Task <ActionResult <int> > CreateAsync(int datasetId, [FromBody] RecordCreation recordCreation)
        {
            int recordId;

            try
            {
                recordId = await _recordService.CreateAsync(datasetId, recordCreation);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok(recordId));
        }
Esempio n. 3
0
        public RecordEntity Create(RecordCreation creation)
        {
            var entity = _autoMapper.Map <RecordEntity>(creation);

            entity.Properties = creation.Properties
                                .Where(x => x.Value.HasValue)
                                .Select((x) => new PropertyEntity
            {
                SeriesId = x.Key,
                Value    = x.Value.ToString()
            })
                                .ToList();

            return(entity);
        }
Esempio n. 4
0
        public async Task <ValidationResult> AgainstInvalidRecordCreationAsync(int?userId, int datasetId, RecordCreation record)
        {
            var result = new ValidationResult();

            if (userId.HasValue)
            {
                await _userValidator.UserOwnsDatasetAsync(userId.Value, datasetId, result);
            }

            if (record.Notes != null)
            {
                foreach (var note in record.Notes)
                {
                    _noteValidator.NoteTextHasValidLength(note.Text, result);
                }
            }

            if (record.Properties.Keys.Count > 0)
            {
                await _datasetValidator.DatasetContainsSeriesAsync(datasetId, new List <int>(record.Properties.Keys), result);

                foreach (var property in record.Properties)
                {
                    if (property.Value.HasValue)
                    {
                        await _propertyValidator.PropertyValueIsValid(property.Key, property.Value.Value, result);
                    }
                }
            }

            return(result);
        }