public void DeleteMedia(Guid mediaId)
        {
            var media = GetMediaById(mediaId);

            if (media != null)
            {
                context.Remove(media);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, MediaEditViewModel vm)
        {
            Media changedmedia = await _dbContext.medias.Include(x => x.Category).FirstOrDefaultAsync(x => x.Id == id);

            changedmedia.Rating      = vm.Rating;
            changedmedia.CategoryId  = vm.CategoryId;
            changedmedia.Title       = vm.Title;
            changedmedia.Description = vm.Description;
            changedmedia.Creator     = vm.Creator;
            changedmedia.Date        = vm.Date;
            changedmedia.Watched     = vm.Watched;

            var media = _dbContext.medias.SingleOrDefault(a => a.Id == id);

            _dbContext.Remove(media);
            _dbContext.medias.Update(changedmedia);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }