예제 #1
0
        public async Task <ActionResult <FileDetailsViewModels> > UploadFile([FromForm] UploadImageCommand imageCommand)
        {
            var file = imageCommand.File;

            if (file.Length > 0)
            {
                var details = new FileDetails
                {
                    Size         = file.Length,
                    Name         = file.FileName,
                    AddedDate    = DateTime.UtcNow,
                    LastModified = DateTime.UtcNow,
                    ContentType  = file.ContentType,
                    Description  = imageCommand.Description,
                    Tags         = imageCommand.Tags
                };

                var fileDetails = await _storageService.UploadFileAsync(file.OpenReadStream(), details);

                return(Ok(ViewModelsMapper.ConvertFileDetailsToFileDetailsViewModels(fileDetails)));
            }
            else
            {
                return(BadRequest("File is required."));
            }
        }
        public async Task <ImageResponse> UploadImage(ImageUploadDto model)
        {
            try
            {
                if (!SecurityHandler.IsValidPassword(model?.password))
                {
                    throw new UnauthorizedAccessException();
                }

                var filename = ContentDispositionHeaderValue
                               .Parse(model.file.ContentDisposition)
                               .FileName
                               .ToString().Trim('"');

                var fileStream = model.file.OpenReadStream();

                var cmd = new UploadImageCommand(model, fileStream, filename);

                var imageId = await UploadImageCommandHandler.HandleAsync(cmd).ConfigureAwait(false);

                return(await Task.FromResult(GetImageById(imageId.ToString())).ConfigureAwait(false));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        public async Task <IActionResult> EditWorker(string id, [FromBody] WorkerDto worker)
        {
            try
            {
                var updateWorkerDataCommand = new UpdateWorkerDataCommand
                {
                    Id        = id,
                    FirstName = worker.FirstName,
                    LastName  = worker.LastName
                };
                var result = await _mediator.Send(updateWorkerDataCommand);

                var updateScheduleCommand = new UpdateScheduleCommand
                {
                    Id       = id,
                    Schedule = worker.Schedule
                };
                result = await _mediator.Send(updateScheduleCommand);

                var uploadImageCommand = new UploadImageCommand
                {
                    Id          = id,
                    ImageSource = worker.ImageSource
                };
                result = await _mediator.Send(uploadImageCommand);

                await _userService.UpdateUserAsync(id, worker.UserEmail, worker.UserPhoneNumber);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public void PassingImageDtoAndFileInfoGetsCorrectlyConverted()
        {
            var dto = new ImageUploadDto();

            dto.annotation  = "a";
            dto.date        = "date";
            dto.description = "desc";
            dto.inverted    = "i";
            dto.tags        = "one,two,three";
            dto.title       = "title";

            var stream   = new MemoryStream(Encoding.UTF8.GetBytes("asdf"));
            var filename = "testname";

            var cmd = new UploadImageCommand(dto, stream, filename);

            Assert.NotNull(cmd.File);
            Assert.That(cmd.Image.Filename, Is.EqualTo(filename));
            Assert.That(cmd.Image.Thumb.Filename, Is.EqualTo($"thumb_{filename}"));
            Assert.That(cmd.Image.Annotation, Is.EqualTo(dto.annotation));
            Assert.That(cmd.Image.Date, Is.EqualTo(dto.date));
            Assert.That(cmd.Image.Description, Is.EqualTo(dto.description));
            Assert.That(cmd.Image.Inverted, Is.EqualTo(dto.inverted));
            Assert.That(cmd.Image.Title, Is.EqualTo(dto.title));
            Assert.That(cmd.Image.Tags.Length, Is.EqualTo(3));
        }
예제 #5
0
        private HttpContent GetHttpContent <T>(UploadImageCommand <T> command)
        {
            HttpContent content = new StreamContent(command.Image);

            content.Headers.ContentLength = command.Image.Length;
            content.Headers.ContentType   = MediaTypeHeaderValue.Parse(command.ContentType);
            return(content);
        }
예제 #6
0
        public async Task <IActionResult> UploadImage([FromForm] IFormFile formFile)
        {
            var file = await formFile.ToUploadedFileDto();

            var command = new UploadImageCommand(file);
            var url     = await Mediator.Send(command);

            return(Ok(url));
        }
        public async Task <ActionResult <string> > UploadImage([FromForm] UploadImageCommand command)
        {
            var commandResult = await Mediator.Send(command);

            var res = new
            {
                result = commandResult
            };

            return(new JsonResult(res));
        }
예제 #8
0
        public async Task <int> UploadImage([Required][FromForm] IFormFile image, [Required][FromQuery] string type,
                                            CancellationToken cancellationToken)
        {
            var command = new UploadImageCommand
            {
                Name        = image.FileName,
                Type        = type,
                ImageStream = image.OpenReadStream()
            };

            return(await _mediator.Send(command, cancellationToken));
        }
        public async Task <IActionResult> AddUserProfileImage(IFormFile image)
        {
            var userID   = User.FindFirst(c => c.Type == "UserID").Value;
            var cmd      = new UploadImageCommand(image, userID, ImageType.UserProfile);
            var response = await _mediator.Send(cmd);

            if (response == true)
            {
                return(Ok());
            }

            return(BadRequest("Something bad has happened while trying to upload image"));
        }
예제 #10
0
        public async Task <IActionResult> UploadSalonImage(string id, [FromBody] UploadImageCommand command)
        {
            try
            {
                command.Id = id;
                var result = await _mediator.Send(command);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
예제 #11
0
        void PlayerViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case "IsLoading":
                ReloadCommand.NotifyCanExecuteChanged();
                NotifyPropertyChanged("StatusBrush");
                UploadImageCommand.NotifyCanExecuteChanged();
                break;

            case "Error":
                NotifyPropertyChanged("StatusBrush");
                ReloadCommand.NotifyCanExecuteChanged();
                break;

            case "PlayerName":
                NotifyPropertyChanged("Title");
                NotifyPropertyChanged("CleanName");
                break;

            case "IsScreenUploaded":
                UploadImageCommand.NotifyCanExecuteChanged();
                AddReportCommand.NotifyCanExecuteChanged();
                break;

            case "DrawUserInfo":
                NotifyPropertyChanged("Screenshot");
                break;

            case "ScreenshotDate":
                infoScreenshot = DrawInfo(screenshot);
                NotifyPropertyChanged("Screenshot");
                break;

            case "Screenshot":
                SaveImageCommand.NotifyCanExecuteChanged();
                UploadImageCommand.NotifyCanExecuteChanged();
                if (screenshot == null)
                {
                    infoScreenshot = null;
                    GC.Collect();
                }
                break;

            case "ScreenshotTaken":
                NotifyPropertyChanged("StatusBrush");
                break;
            }
        }
예제 #12
0
        private Uri GetRequestUri <T>(UploadImageCommand <T> command)
        {
            string requestUri = $"{this.GetMessageBase<T>()}/{command.Id}/images";
            List <KeyValuePair <string, string> > queryStringParameters = new List <KeyValuePair <string, string> >();

            queryStringParameters.AddRange(this.GetAdditionalParameters(command.AdditionalParameters));
            if (command.Parameters != null)
            {
                IUploadImageParametersBuilder parametersBuilder = this.uploadParametersBuilderFactory.GetParameterBuilder(command.Parameters);
                queryStringParameters.AddRange(parametersBuilder.GetUploadImageParameters(command.Parameters));
            }

            queryStringParameters.ForEach(x => { requestUri = QueryHelpers.AddQueryString(requestUri, x.Key, x.Value); });
            return(new Uri(requestUri));
        }
예제 #13
0
        public CatalogCategoryViewModel(Enums.TYPE categoryType)
        {
            this.itemsModel            = new ItemsModel();
            this.category              = categoryType;
            Title                      = ((Enums.TYPE)categoryType).ToString();
            ItemsVM                    = new ObservableCollection <ItemViewModel>();
            ItemsVM.CollectionChanged += ItemsVM_CollectionChanged;
            generateAndFilterCollectionFromModel();

            UploadImage              = new UploadImageCommand();
            UploadImage.UploadEvent += Image_UploadEvent;

            DeleteItem = new DeleteItemCommand();
            DeleteItem.DeleteItemViewModelEvent += ItemVM_DeleteEvent;
        }
예제 #14
0
 public HttpRequestMessage GetRequestMessage <T>(UploadImageCommand <T> command)
 {
     return(this.GetRequestMessage <T>(this.GetRequestUri <T>(command), this.GetHttpContent <T>(command), HttpMethod));
 }
예제 #15
0
        public async Task <ActionResult <ImageVm> > Upload(int id, [FromForm] UploadImageCommand command)
        {
            command.HairSalonId = id;

            return(await Mediator.Send(command));
        }
예제 #16
0
 public override void RaiseCommandCanExecuteChanged()
 {
     UploadImageCommand.RaiseCanExecuteChanged();
     DownloadImageCommand.RaiseCanExecuteChanged();
     ResetImageCommand.RaiseCanExecuteChanged();
 }
 public UploadImageHttpApiCommand(UploadImageCommand <T> command, IRequestMessageBuilderFactory requestMessageBuilderFactory)
 {
     this.command        = command;
     this.requestBuilder = requestMessageBuilderFactory.GetRequestMessageBuilder <UploadImageRequestMessageBuilder>();
 }