Ejemplo n.º 1
0
        public async Task <Media> UploadHazardPhoto(Hazard hazard, IFormFile file, string uploadsFolderPath, FileUploadChannels channelId = FileUploadChannels.incidencesResolvedOnWeb, bool IsImageFileNotVideo = false)
        {
            var fileName = await _photoStorage.StorePhoto(uploadsFolderPath, file);

            var media = new Media {
                FileName = fileName, DateUploaded = DateTime.Now, FileUploadChannel = channelId, Description = file.FileName, IsVideo = !IsImageFileNotVideo
            };

            hazard.Medias.Add(media);
            await _unitOfWork.CompleteAsync();

            return(media);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UploadIncidencePhotosVideos(Guid incidenceId, IFormFile file, FileUploadChannels channelId)
        {
            try
            {
                // upload photo/video for incidence
                var incidence = await _incidenceRepo.GetIncidence(incidenceId, includeRelated : false);

                if (incidence == null)
                {
                    return(NotFound());
                }

                if (file == null)
                {
                    return(BadRequest("Null file"));
                }
                if (file.Length == 0)
                {
                    return(BadRequest("Empty file"));
                }

                var user = await _userRepo.GetUser(_userRepo.GetLoggedInUserId());

                var userdeployment = await _userRepo.GetUserDeploymentData(_userRepo.GetLoggedInUserId());

                var orgSettings = await _settingsRepo.GetOrganizationSettings(user.OrganizationId);

                var deptSettings = await _settingsRepo.GetDepartmentSettings(userdeployment.DepartmentId);

                var generalSettings = await _settingsRepo.GetGeneralSettings();


                //uploading incidence resolution proof uses the uploader's dept settings|org settings|general settings
                if (!_settingsRepo.ValidateFileType(deptSettings, orgSettings, generalSettings, file))
                {
                    return(BadRequest("Invalid file type"));
                }

                if (!_settingsRepo.ValidateFileSize(deptSettings, orgSettings, generalSettings, file))
                {
                    return(BadRequest("Maximun file size exceeded"));
                }

                var isFilePhotoNotVideo = _settingsRepo.IsImageFileNotVideo(deptSettings, orgSettings, generalSettings, file);

                var uploadsFolderPath = Path.Combine(_host.WebRootPath, "uploads");
                var photo             = await _photoService.UploadPhoto(incidence, file, uploadsFolderPath, channelId, isFilePhotoNotVideo);

                return(Ok(_mapper.Map <Media, MediaResource>(photo)));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Error", "An error occured while performing this operation.");
                return(BadRequest(ModelState));
            }
        }