Ejemplo n.º 1
0
        public int Add([FromBody] Video video)
        {
            _context.Video.Add(video);
            _context.SaveChanges();

            return(video.Id);
        }
Ejemplo n.º 2
0
        public int Add([FromBody] Image image)
        {
            _context.Images.Add(image);
            _context.SaveChanges();

            return(image.Id);
        }
Ejemplo n.º 3
0
        public int Add([FromBody] Music music)
        {
            _context.Music.Add(music);
            _context.SaveChanges();

            return(music.Id);
        }
Ejemplo n.º 4
0
 public void AssignRegisseur(Movie movie, MovieRegisseur regisseur)
 {
     _context.MovieRegisseurCombo.Add(new MovieRegisseurCombo
     {
         MovieId          = movie.Id,
         MovieRegisseurId = regisseur.Id
     });
     _context.SaveChanges();
 }
Ejemplo n.º 5
0
        public void Delete(int id)
        {
            Movie movieToDelete = Get(id);

            _context.Movies.Remove(movieToDelete);
            _context.MovieRegisseurCombo.RemoveRange(_context.MovieRegisseurCombo.Where(m => m.MovieId == id));
            _context.GenreMovieCombo.RemoveRange(_context.GenreMovieCombo.Where(m => m.MovieId == id));
            _context.SaveChanges();
        }
Ejemplo n.º 6
0
 public void AssignGenre(Movie movie, string genre)
 {
     _context.GenreMovieCombo.Add(new GenreMovieCombo
     {
         MovieId      = movie.Id,
         MovieGenreId = _context.MovieGenres.SingleOrDefault(g => g.Naam == genre).Id
     });
     _context.SaveChanges();
 }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "MovieName,Genre,State,Director,Duration,Release")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                db.Movies.Add(movie);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(movie));
        }
Ejemplo n.º 8
0
        public IActionResult Create([FromBody] Image img)
        {
            if (img == null)
            {
                return(BadRequest());
            }

            _context.Images.Add(img);
            _context.SaveChanges();

            return(CreatedAtRoute("GetImages", new { id = img.Id }, img));
        }
Ejemplo n.º 9
0
        public ActionResult Create([Bind(Include = "ActorId,FirstName,LastName,Born,KnownFor,PersonalDetails,MovieName")] Actor actor)
        {
            if (ModelState.IsValid)
            {
                db.Actors.Add(actor);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MovieName = new SelectList(db.Movies, "MovieName", "Genre", actor.MovieName);
            return(View(actor));
        }
Ejemplo n.º 10
0
        public IActionResult Create([FromBody] Video vdo)
        {
            if (vdo == null)
            {
                return(BadRequest());
            }

            _context.Videos.Add(vdo);
            _context.SaveChanges();

            return(CreatedAtRoute("GetImages", new { id = vdo.Id }, vdo));
        }
Ejemplo n.º 11
0
        public IActionResult Add(string Name, string Url, string Description)
        {
            Platform platform = new Platform();

            platform.Name        = Name;
            platform.Url         = Url;
            platform.Description = Description;
            db.Platforms.Add(platform);
            db.SaveChanges();
            return(Ok(new ResWrapper {
                Status = "OK", args = platform
            }));
        }
Ejemplo n.º 12
0
 public void RemoveSubject(Subject subjectToRemove)
 {
     using (var ctx = new MediaContext()) {
         ctx.Subjects.Remove(subjectToRemove);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 13
0
        public async Task<bool> AddMedia(StorageFile media)
        {
            try
            {
                Media newMedia = new Media();

                if ((bool)localSettings.Values["EnableOxford"])
                {
                    AnalysisResult analysisResult = await DoVision(media);
                    Emotion[] emotions = await DoFeel(media);
                    newMedia = ExtractFeatures(analysisResult, emotions);
                }

                newMedia.IsMerged = false;
                newMedia.MediaName = media.Name;
                localSettings.Values["LastImageName"] = media.Name;
                newMedia.CaptureDate = media.DateCreated.DateTime;
                using (var db = new MediaContext())
                {
                    db.Medias.Add(newMedia);
                    db.SaveChanges();
                }
                MediaList.Add(newMedia);
            }
            catch (Exception)
            {

            }
            return true;
        }
        public bool DeleteUser(User user)
        {
            var result = false;

            using (var mediaContext = new MediaContext())
            {
                using (var transaction = mediaContext.Database.BeginTransaction())
                {
                    try
                    {
                        user.IsDeleted = true;
                        mediaContext.Users.Add(user);
                        mediaContext.SaveChanges();
                        result = true;
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 15
0
 public void RemoveCategory(Category categoryToRemove)
 {
     using (var ctx = new MediaContext()) {
         ctx.Categories.Remove(categoryToRemove);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 16
0
 public Subject AddSubject(Subject newSubject)
 {
     using (var ctx = new MediaContext()) {
         var result = ctx.Subjects.Add(newSubject);
         ctx.SaveChanges();
         return(result);
     }
 }
Ejemplo n.º 17
0
 public Category AddCategory(Category newCategory)
 {
     using (var ctx = new MediaContext()) {
         var result = ctx.Categories.Add(newCategory);
         ctx.SaveChanges();
         return(result);
     }
 }
Ejemplo n.º 18
0
 public void AddMediaContainer(MediaContainer containerToAdd)
 {
     using (var ctx = new MediaContext())
     {
         ctx.Containers.Add(containerToAdd);
         OnContainersAdded(new MediaContainer[] { containerToAdd });
         ctx.SaveChanges();
     }
 }
        public static MediaContext Generate()
        {
            var options = CreateNewContextOptions();
            var context = new MediaContext(options);

            CreateTestData(ref context);
            context.SaveChanges();

            return(context);
        }
Ejemplo n.º 20
0
        public ImagesController(MediaContext context)
        {
            _context = context;

            if (_context.Images.Count() == 0)
            {
                _context.Images.Add(new Image {
                    Name = "IMAGE001", Path = "/Users/rest"
                });
                _context.SaveChanges();
            }
        }
Ejemplo n.º 21
0
 public void RemoveMediaContainer(int idOfContainerToRemove)
 {
     using (var ctx = new MediaContext())
     {
         var container = ctx.Containers.Find(idOfContainerToRemove);
         if (container != null)
         {
             ctx.Containers.Remove(container);
             OnContainersRemoved(new MediaContainer[] { container });
             ctx.SaveChanges();
         }
     }
 }
Ejemplo n.º 22
0
        // Needs performance improvements
        private void CreateEntriesFromFileSystem(DirectoryInfo dir, IEnumerable <FileTypes> filter, bool recurse = false)
        {
            try {
                // Get all entries
                IEnumerable <FileSystemInfo> fsEntries = dir.GetFileSystemInfos();
                // Create filtering hashset
                HashSet <string> filterExtensions = FileExtension.GetFsExtensionFilter(filter?.ToArray());

                using (var ctx = new MediaContext()) {
                    // Find a possible parent entry for the current dir
                    string currentParentId = FileSystemItem.GenerateId(dir.Parent.FullName);

                    // Create the currently scanned dir as object
                    var currentDirObj = ctx.Items.Add(FileSystemItem.CreateFromFileSystemInfo(dir)) as DirectoryItem;
                    // if we have a current parent, add it
                    if (ctx.Items.FirstOrDefault(e => e.Id == currentParentId) is DirectoryItem currentDirParent)
                    {
                        currentDirObj.Parents.Add(currentDirParent);
                    }

                    IEnumerable <FileSystemInfo> fsFileEntries =
                        fsEntries.Where(e =>
                                        !File.GetAttributes(e.FullName).HasFlag(FileAttributes.Directory) &&
                                        (!filterExtensions.Any() ||
                                         filterExtensions.Contains(e.Extension)));
                    if (fsFileEntries.Any())
                    {
                        foreach (var fsFileEntry in fsFileEntries)
                        {
                            FileSystemItem currentEntryObj = ctx.Items.Add(
                                FileSystemItem.CreateFromFileSystemInfo(fsFileEntry));
                            currentEntryObj.Parents.Add(currentDirObj);
                            currentDirObj.Children.Add(currentEntryObj);
                        }
                    }

                    ctx.SaveChanges();
                }

                // Recurse sub-dirs
                if (recurse)
                {
                    foreach (var fsDir in fsEntries.Where(e => File.GetAttributes(e.FullName).HasFlag(FileAttributes.Directory)))
                    {
                        CreateEntriesFromFileSystem(new DirectoryInfo(fsDir.FullName), filter, recurse);
                    }
                }
            } catch (Exception ex) {
            }
        }
Ejemplo n.º 23
0
        public async Task <Guid> CreateFileAsync(CreateMediaItemServiceModel serviceModel)
        {
            var checksum = this.checksumService.GetMd5(serviceModel.File);

            var existingMediaItemVersion = context.MediaItemVersions.FirstOrDefault(x => x.Checksum == checksum && x.Filename == Path.GetFileNameWithoutExtension(serviceModel.File.FileName) && x.IsActive);

            if (existingMediaItemVersion != null)
            {
                return(existingMediaItemVersion.MediaItemId);
            }

            var mediaItem = new MediaItem
            {
                OrganisationId = serviceModel.OrganisationId,
                IsProtected    = false
            };

            context.MediaItems.Add(mediaItem.FillCommonProperties());

            var mediaItemVersion = new MediaItemVersion
            {
                MediaItemId = mediaItem.Id,
                Filename    = Path.GetFileNameWithoutExtension(serviceModel.File.FileName),
                Extension   = Path.GetExtension(serviceModel.File.FileName),
                Folder      = serviceModel.OrganisationId.ToString(),
                MimeType    = MimeUtility.GetMimeMapping(Path.GetExtension(serviceModel.File.FileName)),
                Size        = serviceModel.File.Length,
                Checksum    = checksum,
                CreatedBy   = serviceModel.Username,
                Version     = 1
            };

            context.MediaItemVersions.Add(mediaItemVersion.FillCommonProperties());

            var mediaItemTranslation = new MediaItemTranslation
            {
                MediaItemVersionId = mediaItemVersion.Id,
                Language           = serviceModel.Language,
                Name = Path.GetFileNameWithoutExtension(serviceModel.File.FileName)
            };

            context.MediaItemTranslations.Add(mediaItemTranslation.FillCommonProperties());

            context.SaveChanges();

            await this.mediaRepository.CreateFileAsync(mediaItemVersion.Id, serviceModel.OrganisationId.ToString(), serviceModel.File, serviceModel.File.FileName);

            return(mediaItem.Id);
        }
Ejemplo n.º 24
0
 public void AssignGezienStatus(int movieId, string userId, int gezienStatus)
 {
     if (_context.UserMovieGezienStatus.Count() != 0 && _context.UserMovieGezienStatus.Any(x => x.MovieId == movieId && x.UserId == userId))
     {
         _context.UserMovieGezienStatus.SingleOrDefault(x => x.MovieId == movieId && x.UserId == userId).MovieGezienStatus =
             _context.MovieGezienStatus.SingleOrDefault(s => s.Id == gezienStatus);
     }
     else
     {
         _context.UserMovieGezienStatus.Add(new UserMovieGezienStatus {
             MovieId = movieId, UserId = userId, MovieGezienStatus = _context.MovieGezienStatus.SingleOrDefault(s => s.Id == gezienStatus)
         });
     }
     _context.SaveChanges();
 }
Ejemplo n.º 25
0
 public void AssignRatingReview(int movieId, string userId, int eigenRating, string eigenReview = null)
 {
     if (_context.MovieRatingReview.Any(x => x.MovieId == movieId && x.UserId == userId))
     {
         _context.MovieRatingReview.SingleOrDefault(x => x.MovieId == movieId && x.UserId == userId).Rating = eigenRating;
         _context.MovieRatingReview.SingleOrDefault(x => x.MovieId == movieId && x.UserId == userId).Review = eigenReview;
     }
     else
     {
         _context.MovieRatingReview.Add(new MovieRatingReview {
             MovieId = movieId, UserId = userId, Rating = eigenRating, Review = eigenReview
         });
     }
     _context.SaveChanges();
 }
Ejemplo n.º 26
0
        // Request 10
        public IActionResult Update(long Id, string field, string value)
        {
            var query = (from Person in db.People
                         where Person.Id == Id
                         select Person);

            if (!query.Any())
            {
                return(NotFound(new ResWrapper {
                    Status = "NotFound", args = new { Id, field, value }
                }));
            }

            var person = query.Single();

            string OldValue = "";

            //Fields fullname birthdate deathdate
            switch (field.ToLower())
            {
            case "fullname":
                OldValue        = person.FullName;
                person.FullName = value;
                break;

            case "birthdate":
                OldValue         = person.BirthDate.ToString();
                person.BirthDate = DateTime.Parse(value);
                break;

            case "deathdate":
                OldValue         = person.DeathDate.ToString();
                person.DeathDate = DateTime.Parse(value);
                break;

            default:
                return(BadRequest(new ResWrapper {
                    Status = "InvalidField", args = new { Id, field, value }
                }));
            }

            db.SaveChanges();

            return(Ok(new ResWrapper {
                Status = "OK", args = new { Id, field, value }, Data = new { OldValue, person }
            }));
        }
Ejemplo n.º 27
0
        private static void SeedMedia(MediaContext context, IChecksumService checksumService, string storageConnectionString, Guid mediaId, Guid mediaVersionId, string mediaUrl)
        {
            if (!context.MediaItems.Any(x => x.Id == mediaId))
            {
                var container = new BlobContainerClient(storageConnectionString, MediaConstants.General.ContainerName);

                container.CreateIfNotExists();

                var blob = container.GetBlobClient($"{mediaVersionId}{Path.GetExtension(mediaUrl)}");

                using (var stream = new MemoryStream(File.ReadAllBytes(mediaUrl)))
                {
                    if (!blob.Exists())
                    {
                        blob.Upload(stream);
                    }

                    var mediaItem = new MediaItem
                    {
                        Id          = mediaId,
                        IsProtected = false
                    };

                    context.MediaItems.Add(mediaItem.FillCommonProperties());

                    var mediaItemVersion = new MediaItemVersion
                    {
                        Id          = mediaVersionId,
                        MediaItemId = mediaId,
                        Checksum    = checksumService.GetMd5(stream),
                        Filename    = Path.GetFileNameWithoutExtension(mediaUrl),
                        Extension   = Path.GetExtension(mediaUrl),
                        Folder      = MediaConstants.General.ContainerName,
                        MimeType    = MimeUtility.GetMimeMapping(Path.GetExtension(mediaUrl)),
                        Size        = blob.GetProperties().Value.ContentLength,
                        CreatedBy   = "system",
                        Version     = 1
                    };

                    context.MediaItemVersions.Add(mediaItemVersion.FillCommonProperties());

                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 28
0
        public async Task RemoveMedia(Media media)
        {
            try
            {
                Media toDeleteMedia = MediaList.Where(x => x.MediaName == media.MediaName).FirstOrDefault();
                using (var db = new MediaContext())
                {
                    db.Medias.Remove(toDeleteMedia);
                    db.SaveChanges();
                }
                MediaList.Remove(toDeleteMedia);
                StorageFile fileToDelete = await localFolder.GetFileAsync(media.MediaName);
                await fileToDelete.DeleteAsync();
            }
            catch (Exception ex)
            {

                
            }
        }
Ejemplo n.º 29
0
        public async Task RemoveMedia(MediaGroup mediaG)
        {
            try
            {
                MediaGroup toDeleteMediaG = MediaGroupList.Where(x => x.CompostionFileName == mediaG.CompostionFileName).FirstOrDefault();
                using (var db = new MediaContext())
                {
                    db.MediaGroups.Remove(toDeleteMediaG);
                    db.SaveChanges();
                }
                MediaGroupList.Remove(toDeleteMediaG);
                StorageFile fileToDelete = await localFolder.GetFileAsync(mediaG.CompostionFileName + ".cmp");
                await fileToDelete.DeleteAsync();
            }
            catch (Exception ex)
            {


            }
        }
Ejemplo n.º 30
0
        public async Task <IActionResult> Upload()
        {
            var files = Request.Form.Files;

            foreach (var file in files)
            {
                if (file.Length > 0)
                {
                    var extension = Path.GetExtension(file.FileName);
                    var fileName  = string.Format(@"{0}{1}", Guid.NewGuid().ToString("N"), extension);
                    var filePath  = Path.Combine(_uploads, fileName);
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        await file.CopyToAsync(fileStream);
                    }

                    using (var db = new MediaContext())
                    {
                        var media = new Media
                        {
                            CreatedTimeStamp = DateTime.UtcNow,
                            FileName         = fileName,
                            Id   = Guid.NewGuid().ToString("N"),
                            Name = file.FileName,
                            Type = file.ContentType
                        };
                        db.Medias.Add(media);
                        db.SaveChanges();
                    }
                }
            }

            OkResult okResult = Ok();

            return(okResult);
        }