Esempio n. 1
0
        public async Task <IActionResult> CreateProject([FromBody] ProjectInputModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }

            var project = new Project()
            {
                Title     = inputModel.Title,
                Location  = inputModel.Location,
                StartDate = inputModel.StartDate,
                EndDate   = inputModel.EndDate,
                Ongoing   = inputModel.Ongoing,
                Summary   = inputModel.Summary
            };

            if (!string.IsNullOrEmpty(inputModel.Image))
            {
                var authority = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}";

                var image = await _uploadImageService.UploadImage(inputModel.Image, authority);

                project.Image = image;
            }

            _unitOfWork.ProjectsRepository.Add(project);

            await _unitOfWork.CompleteAsync();

            return(this.Ok(project));
        }
Esempio n. 2
0
        public async Task <IActionResult> UploadImage([FromForm] IFormCollection collection)
        {
            var workingDirectory = Directory.GetCurrentDirectory();
            var projectDirectory = Directory.GetParent(workingDirectory)?.Parent?.Parent?.Parent?.FullName + @"/UploadImageAPI/Images";

            var uploadedFiles = collection.Files;

            if (uploadedFiles.Count > 0)
            {
                var isSucceed = await uploadedFiles.ToList()
                                .ForEachAsync(async i => await _imageService.UploadImage(i, projectDirectory));

                return(Ok(isSucceed));
            }

            return(NotFound(false));
        }
Esempio n. 3
0
 public Response UploadImage([FromForm] UploadImageRequest request)
 {
     return(_uploadImageService.UploadImage(request));
 }