Beispiel #1
0
        public async Task <IActionResult> Upload(long parameterId, IFormFile file)
        {
            var parameter = await _parameterRepository.GetAsync(parameterId);

            if (parameter == null)
            {
                return(NotFound());
            }
            if (file == null)
            {
                return(BadRequest("Null file"));
            }
            if (file.Length == 0)
            {
                return(BadRequest("Empty file"));
            }
            if (file.Length > _photoSettings.MaxBytes)
            {
                return(BadRequest("Max file size exceeded"));
            }
            if (!_photoSettings.IsSupported(file.FileName))
            {
                return(BadRequest("Invalid file type"));
            }

            string uploadsFolderPath = Path.Combine(_host.WebRootPath, "clientapp", "uploads", "parameters");

            if (!Directory.Exists(uploadsFolderPath))
            {
                Directory.CreateDirectory(uploadsFolderPath);
            }

            string fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
            string filePath = Path.Combine(uploadsFolderPath, fileName);

            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }

            var figure = new Figure {
                FileName = fileName
            };
            var parameterPhoto = new ParameterFigure {
                Parameter = parameter, Figure = figure
            };

            parameter.ParameterFigures.Add(parameterPhoto);

            await _unitOfWork.CompleteAsync();

            return(Ok(_mapper.Map <Figure, FigureResource>(figure)));
        }
            public async Task <Unit> Handle(UpdateScriptCommand request, CancellationToken cancellationToken)
            {
                var script = await _scriptRepository.GetScriptWithTagsAsync(request.Id);

                if (script == null)
                {
                    throw new NotFoundException(nameof(Script), request.Id);
                }

                script.Id              = request.Id;
                script.Name            = request.Name;
                script.Description     = request.Description;
                script.GroupName       = request.GroupName;
                script.Author          = request.Author;
                script.AccordingTo     = request.AccordingTo;
                script.Notes           = request.Notes;
                script.DefaultLanguage = request.DefaultLanguage;
                script.Modified        = _dateTime.Now;

                RemoveNotAddedTags(request, script);
                AddNewTags(request, script);

                await _unitOfWork.CompleteAsync();

                return(Unit.Value);
            }
            public async Task <Unit> Handle(UpdateParameterCommand request, CancellationToken cancellationToken)
            {
                var script = await _scriptRepository.GetAsync(request.ScriptId);

                var parameter = await _parameterRepository.GetParameterWithAllDependanciesAsync(request.Id);

                if (script == null || parameter == null)
                {
                    throw new NotFoundException(nameof(Parameter), request.Id);
                }

                parameter.Name                = request.Name;
                parameter.Number              = request.Number;
                parameter.Description         = request.Description;
                parameter.ValueType           = request.ValueType;
                parameter.Value               = request.Value;
                parameter.VisibilityValidator = request.VisibilityValidator;
                parameter.DataValidator       = request.DataValidator;
                parameter.Unit                = request.Unit;
                parameter.ValueOptionSetting  = request.ValueOptionSetting;
                parameter.Context             = request.Context;
                parameter.GroupName           = request.GroupName;
                parameter.AccordingTo         = request.AccordingTo;
                parameter.Notes               = request.Notes;

                _scriptMappingProfile.UpdateValueOptions(request.ValueOptions, parameter);
                _scriptMappingProfile.RemoveNotAddedValueOptions(request.ValueOptions, parameter);
                _scriptMappingProfile.AddNewValueOptions(request.ValueOptions, parameter);

                script.Modified = _dateTime.Now;

                await _unitOfWork.CompleteAsync();

                return(MediatR.Unit.Value);
            }
            public async Task <ScriptCreated> Handle(CreateScriptCommand request, CancellationToken cancellationToken)
            {
                var script = new Script
                {
                    Id              = 0,
                    Name            = request.Name,
                    Description     = request.Description,
                    GroupName       = request.GroupName,
                    Author          = request.Author,
                    AccordingTo     = request.AccordingTo,
                    Notes           = request.Notes,
                    DefaultLanguage = request.DefaultLanguage,
                    Added           = _dateTime.Now,
                    Modified        = _dateTime.Now,
                    Version         = "1"
                };

                RemoveNotAddedTags(request, script);
                AddNewTags(request, script);

                await _scriptRepository.AddAsync(script);

                await _unitOfWork.CompleteAsync(cancellationToken);

                await _mediator.Publish(new ScriptCreated { Id = script.Id }, cancellationToken);

                // return Unit.Value; HACK: Needs to be this
                return(new ScriptCreated {
                    Id = script.Id
                });
            }
            public async Task <Unit> Handle(UploadFigureCommand request, CancellationToken cancellationToken)
            {
                var parameter = await _parameterRepository.GetAsync(request.ParameterId);

                if (parameter == null)
                {
                    throw new NotFoundException(nameof(Figure), request.ParameterId);
                }
                if (request.File == null)
                {
                    throw new BadRequestException(nameof(Figure), "Null file");
                }
                if (request.File.Length == 0)
                {
                    throw new BadRequestException(nameof(Figure), "Empty file");
                }
                if (request.File.Length > _photoSettings.MaxBytes)
                {
                    throw new BadRequestException(nameof(Figure), "Max file size exceeded");
                }
                if (!_photoSettings.IsSupported(request.File.FileName))
                {
                    throw new BadRequestException(nameof(Figure), "Invalid file type");
                }

                string uploadsFolderPath = Path.Combine(_host.WebRootPath, "clientapp", "uploads", "parameters");

                if (!Directory.Exists(uploadsFolderPath))
                {
                    Directory.CreateDirectory(uploadsFolderPath);
                }

                string fileName = Guid.NewGuid().ToString() + Path.GetExtension(request.File.FileName);
                string filePath = Path.Combine(uploadsFolderPath, fileName);

                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await request.File.CopyToAsync(stream);
                }

                var figure = new Figure {
                    FileName = fileName
                };
                var parameterPhoto = new ParameterFigure {
                    Parameter = parameter, Figure = figure
                };

                parameter.ParameterFigures.Add(parameterPhoto);

                await _unitOfWork.CompleteAsync();

                return(Unit.Value);
            }
            public async Task <Unit> Handle(DeleteValueOptionTranslationCommand request, CancellationToken cancellationToken)
            {
                var valueOptionTranslation = await _valueOptionTranslationRepository.GetValueOptionTranslation(request.Id);

                if (valueOptionTranslation == null)
                {
                    throw new NotFoundException(nameof(DeleteValueOptionTranslationCommand), request.Id);
                }

                _valueOptionTranslationRepository.RemoveValueOptionTranslation(valueOptionTranslation);
                await _unitOfWork.CompleteAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <Unit> Handle(DeleteScriptCommand request, CancellationToken cancellationToken)
            {
                var script = await _scriptRepository.GetAsync(request.Id);

                if (script == null)
                {
                    throw new NotFoundException(nameof(Script), request.Id);
                }

                _scriptRepository.Remove(script);
                await _unitOfWork.CompleteAsync(cancellationToken);

                return(Unit.Value);
            }
Beispiel #8
0
            public async Task <Unit> Handle(DeleteParameterCommand request, CancellationToken cancellationToken)
            {
                var parameter = await _parameterRepository.GetAsync(request.Id);

                if (parameter == null)
                {
                    throw new NotFoundException(nameof(Parameter), request.Id);
                }

                _parameterRepository.Remove(parameter);
                await _unitOfWork.CompleteAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <TagCreated> Handle(CreateTagCommand request, CancellationToken cancellationToken)
            {
                var tag = new Tag
                {
                    Id   = 0,
                    Name = request.Name
                };

                await _tagRepository.AddAsync(tag);

                await _unitOfWork.CompleteAsync(cancellationToken);

                return(new TagCreated {
                    Id = tag.Id
                });
            }
            public async Task <Unit> Handle(CreateValueOptionTranslationCommand request, CancellationToken cancellationToken)
            {
                var valueOptionTranslation = new ValueOptionTranslation
                {
                    Id            = 0,
                    ValueOptionId = request.ValueOptionId,
                    Description   = request.Description,
                    Language      = request.Language,
                    Name          = request.Name
                };

                await _translationRepository.AddValueOptionTranslationAsync(valueOptionTranslation);

                await _unitOfWork.CompleteAsync();

                return(Unit.Value);
            }
            public async Task <Unit> Handle(CreateScriptTranslationCommand request, CancellationToken cancellationToken)
            {
                var scriptTranslation = new ScriptTranslation
                {
                    Id          = 0,
                    Name        = request.Name,
                    Description = request.Description,
                    ScriptId    = request.ScriptId,
                    Notes       = request.Notes,
                    Language    = request.Language
                };

                await _translationRepository.AddScriptTranslationAsync(scriptTranslation);

                await _unitOfWork.CompleteAsync();

                return(Unit.Value);
            }
Beispiel #12
0
            public async Task <Unit> Handle(UpdateValueOptionTranslationCommand request, CancellationToken cancellationToken)
            {
                var valueOptionTranslation = await _translationRepository.GetValueOptionTranslation(request.Id);

                if (valueOptionTranslation == null)
                {
                    throw new NotFoundException(nameof(UpdateValueOptionTranslationCommand), request.Id);
                }

                valueOptionTranslation.ValueOptionId = request.ValueOptionId;
                valueOptionTranslation.Description   = request.Description;
                valueOptionTranslation.Language      = request.Language;
                valueOptionTranslation.Name          = request.Name;

                await _unitOfWork.CompleteAsync();

                return(Unit.Value);
            }
Beispiel #13
0
            public async Task <Unit> Handle(CreateParameterTranslationCommand request, CancellationToken cancellationToken)
            {
                var parameterTranslation = new ParameterTranslation
                {
                    Id          = 0,
                    ParameterId = request.ParameterId,
                    Description = request.Description,
                    GroupName   = request.GroupName,
                    Notes       = request.Notes,
                    Language    = request.Language
                };

                await _translationRepository.AddParameterTranslationAsync(parameterTranslation);

                await _unitOfWork.CompleteAsync();

                return(Unit.Value);
            }
Beispiel #14
0
            public async Task <Unit> Handle(UpdateParameterTranslationCommand request, CancellationToken cancellationToken)
            {
                var parameterTranslation = await _translationRepository.GetParameterTranslation(request.Id);

                if (parameterTranslation == null)
                {
                    throw new NotFoundException(nameof(UpdateParameterTranslationCommand), request.Id);
                }

                parameterTranslation.Description = request.Description;
                parameterTranslation.GroupName   = request.GroupName;
                parameterTranslation.Language    = request.Language;
                parameterTranslation.Notes       = request.Notes;
                parameterTranslation.ParameterId = request.ParameterId;

                await _unitOfWork.CompleteAsync();

                return(Unit.Value);
            }
            public async Task <Unit> Handle(DetachFigureCommand request, CancellationToken cancellationToken)
            {
                var parameter = await _parameterRepository.GetParameterWithAllDependanciesAsync(request.ParameterId);

                if (parameter == null)
                {
                    throw new NotFoundException(nameof(Parameter), request.ParameterId);
                }

                var parameterFigure = parameter.ParameterFigures.FirstOrDefault(pf => pf.FigureId == request.FigureId);

                if (parameterFigure == null)
                {
                    throw new NotFoundException(nameof(ParameterFigure), request.FigureId);
                }

                parameter.ParameterFigures.Remove(parameterFigure);

                await _unitOfWork.CompleteAsync();

                return(Unit.Value);
            }
            public async Task <Unit> Handle(CreateParameterCommand request, CancellationToken cancellationToken)
            {
                var parameter = new Parameter
                {
                    Id                  = 0,
                    ScriptId            = request.ScriptId,
                    Name                = request.Name,
                    Number              = request.Number,
                    Description         = request.Description,
                    ValueType           = request.ValueType,
                    Value               = request.Value,
                    VisibilityValidator = request.VisibilityValidator,
                    DataValidator       = request.DataValidator,
                    Unit                = request.Unit,
                    ValueOptionSetting  = request.ValueOptionSetting,
                    Context             = request.Context,
                    GroupName           = request.GroupName,
                    AccordingTo         = request.AccordingTo,
                    Notes               = request.Notes,
                };

                _scriptMappingProfile.UpdateValueOptions(request.ValueOptions, parameter);
                _scriptMappingProfile.RemoveNotAddedValueOptions(request.ValueOptions, parameter);
                _scriptMappingProfile.AddNewValueOptions(request.ValueOptions, parameter);

                var script = await _scriptRepository.GetAsync(request.ScriptId);

                if (script == null)
                {
                    throw new NotFoundException(nameof(CreateParameterCommand), request.ScriptId);
                }
                script.Modified = _dateTime.Now;

                await _parameterRepository.AddAsync(parameter);

                await _unitOfWork.CompleteAsync(cancellationToken);

                return(MediatR.Unit.Value);
            }