Beispiel #1
0
        public MediaDto Upload(string filePath, string fileName, string mediaMappedPath)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new Exception();
            }

            Logic.Entities.Media newMedia = _mediaManager.CreateMediaEntity(filePath, fileName, mediaMappedPath);

            _mediaManager.UploadMediaEntityToFileSystem(newMedia);

            _mediaRepository.Insert(newMedia);

            CurrentUnitOfWork.SaveChanges();

            return(_objectMapper.Map <MediaDto>(newMedia));
        }
        private void BindMediaResources(DamageReport damage)
        {
            int[] mediaResourceIds = damage.MediaResources.Select(mr => mr.Id).ToArray();

            foreach (int mediaResourceId in mediaResourceIds)
            {
                Logic.Entities.Media dbMedia = _mediaRepository.Get(mediaResourceId);

                if (dbMedia == null)
                {
                    throw new InvalidRequestException();
                }

                damage.MediaResources.RemoveAll(mr => mr.Id == mediaResourceId);

                damage.MediaResources.Add(dbMedia);
            }
        }