Exemplo n.º 1
0
        public async Task <IActionResult> ChangeAvatar([FromForm] ChangeAvatarViewModel model)
        {
            var picture     = FormFileHelper.ConvertFileToBytes(model.Picture);
            var contentType = model.Picture.ContentType;

            await _employeeService.UpdatePicture(CurrentUser.UserId, picture, contentType);

            return(NoContent());
        }
        public IResult Delete(Image image)
        {
            var check = BusinessRules.Run(CheckTheCarExists(image.CarId));

            if (check != null)
            {
                return(check);
            }

            FormFileHelper.Delete(image.ImagePath);
            _imageDal.Delete(image);
            return(new SuccessResult(Messages.ImageDeleted));
        }
        public IResult Add(IFormFile file, Image image)
        {
            var check = BusinessRules.Run(CheckImageLimit(image.CarId), CheckTheCarExists(image.CarId));

            if (check != null)
            {
                return(check);
            }

            image.ImagePath = FormFileHelper.Add(file);
            image.Date      = DateTime.Now;
            _imageDal.Add(image);
            return(new SuccessResult(Messages.ImageAdded));
        }
        public async Task <IActionResult> UploadFile(List <IFormFile> files)
        {
            if (!files.Any())
            {
                // Nothing uploaded, return bad request
                return(BadRequest());
            }

            // Store raw solrQueryResponse as a string
            var rawSolrQueryResponse = FormFileHelper.ConvertToString(files.First());

            // Store object in database
            var guid = SolrResponseStorageService.SaveSolrQueryResponse(rawSolrQueryResponse, SessionService.GetUserId());

            return(RedirectToAction("Explain", new { guid = guid }));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Put([FromForm] AnimalViewModel model)
        {
            var animalDto = _mapper.Map <AnimalDto>(model);

            await _animalService.UpdateAnimalAsync(animalDto);

            if (model.Picture != null)
            {
                var picture     = FormFileHelper.ConvertFileToBytes(model.Picture);
                var contentType = model.Picture.ContentType;

                await _animalService.UpdatePicture(animalDto.AnimalId, picture, contentType);
            }

            return(NoContent());
        }
        public IResult Update(IFormFile file, Image image)
        {
            var check = BusinessRules.Run(CheckTheCarExists(image.CarId));

            if (check != null)
            {
                return(check);
            }

            var result = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "../../../wwwroot")) +
                         _imageDal.Get(i => i.Id == image.Id).ImagePath;

            image.ImagePath = FormFileHelper.Update(file, result);
            image.Date      = DateTime.Now;
            _imageDal.Update(image);
            return(new SuccessResult(Messages.ImageUpdated));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([FromForm] AnimalViewModel model)
        {
            var animalDto = _mapper.Map <AnimalDto>(model);

            var createdId = await _animalService.CreateAnimalAsync(animalDto);

            await _animalDetailsService.CreateAnimalDetailsAsync(new AnimalDetailsDto { AnimalId = (int)createdId.CreatedId });

            if (model.Picture != null)
            {
                var picture     = FormFileHelper.ConvertFileToBytes(model.Picture);
                var contentType = model.Picture.ContentType;

                await _animalService.UpdatePicture((int)createdId.CreatedId, picture, contentType);
            }

            return(Ok(createdId));
        }