コード例 #1
0
        public IActionResult DeleteVideo(int id)
        {
            var video = videoManager.Get().Where(e => e.Id == id).FirstOrDefault();

            videoManager.Delete(video);
            return(RedirectToAction("Index"));
        }
コード例 #2
0
 public async Task <ActionResult> Delete(int Id)
 {
     try
     {
         videoManager.Delete(Id);
         return(View("List", videoManager.GetVideos()));
     }
     catch (Exception e)
     {
         ViewBag.ErrorTitle       = "Server Error";
         ViewBag.ErrorDescription = "Please try again later";
         return(View("~/Views/Shared/ErrorPage.cshtml"));
     }
 }
コード例 #3
0
        public async Task <bool> ReplaceTicket(TicketViewModel newTicketVM)
        {
            // Get the Ticket and ensure it exists
            var ticketToUpdate = _ticketRepo.GetById(newTicketVM.Id);

            if (ticketToUpdate == null)
            {
                _logger.LogError($"\tTicket with id {newTicketVM.Id} was not found in the DB. Nothing was updated.");
                return(false);
            }

            // string to add log message to
            string log = "";

            // If there is at least one video file attached, pass through to video manager to upload
            var videoFiles = newTicketVM.VideoFiles;

            if (videoFiles != null && videoFiles.Count > 0)
            {
                // Upload the videos via VideoManager and return meta data for videos
                var videos = await _videoManager.Upload(videoFiles, newTicketVM.VideoThumbnails);

                foreach (var video in videos)
                {
                    ticketToUpdate.Videos.Add(video);
                    log += $"Video '{video.Title}' uploaded. ";
                }

                // Remove the videoFiles since they have already been uploaded
                newTicketVM.VideoFiles = null;
            }
            else // The following are only done for actions that arent actioned with adding a video
            {
                var newVideoData = newTicketVM.Videos;
                var oldVideoData = ticketToUpdate.Videos;

                // When video/s being removed
                if (newVideoData.Count < oldVideoData.Count)
                {
                    // Delete them from the video storage
                    foreach (var video in oldVideoData)
                    {
                        var potentialVid = newVideoData.FirstOrDefault(x => x.Id == video.Id);

                        if (potentialVid == null)
                        {
                            _videoManager.Delete(video.FileLocation);
                            log += $"Video '{video.Title}' removed. ";
                        }
                    }
                }

                // When no video/s removed, check for changes in notes before the metadata is copied over
                if (newVideoData.Count == oldVideoData.Count)
                {
                    for (int i = 0; i < newVideoData.Count; i++)
                    {
                        var newNotesCount = newVideoData.ToList()[i].Notes.Count;
                        var oldNotesCount = oldVideoData.ToList()[i].Notes.Count;

                        if (newNotesCount != oldNotesCount)
                        {
                            log += $"Number of notes changed from {oldNotesCount} to {newNotesCount} for video '{newVideoData.ToList()[i].Title}'. ";
                        }
                    }
                }

                // Pass the Video metadata since current videos' titles can be changed or notes can be added
                ticketToUpdate.Videos = newTicketVM.Videos;
            }

            // Update values that have been changed
            if (ticketToUpdate.Description != newTicketVM.Description)
            {
                log += $"Description changed from '{ticketToUpdate.Description}' to '{newTicketVM.Description}'. ";
                ticketToUpdate.Description = newTicketVM.Description;
            }

            if (ticketToUpdate.Status != newTicketVM.Status)
            {
                log += $"Status changed from '{ticketToUpdate.Status}' to '{newTicketVM.Status}'. ";
                ticketToUpdate.Status = newTicketVM.Status;
            }

            // If the ticket's name changes, the project also needs to update
            if (ticketToUpdate.Name != newTicketVM.Name)
            {
                log += $"Name changed from '{ticketToUpdate.Name}' to '{newTicketVM.Name}'. ";
                ticketToUpdate.Name = newTicketVM.Name;

                // Get the project to update
                var projectToUpdate = _projectRepo.GetByName(ticketToUpdate.ProjectName);
                if (projectToUpdate == null)
                {
                    _logger.LogError($"\tThe Ticket's project '{newTicketVM.ProjectName}' could not be found in the DB");
                    return(false);
                }

                // Upsert the ticket to the project
                UpsertTicketBaseToProject(projectToUpdate, ticketToUpdate.Id, ticketToUpdate.Name);

                // Update the changed project
                _projectRepo.Update(projectToUpdate).Wait();
            }

            // Ensure there is a log string
            if (log.Length < 1)
            {
                log = "Ticket Updated.";
            }

            ticketToUpdate.EventLog.Add(new Log
            {
                DateAndTime = DateTime.Now,
                Event       = log
            });

            _ticketRepo.Update(ticketToUpdate).Wait();

            return(true);
        }