예제 #1
0
 public void AddVideo(Translation t)
 {
     Video newVideo = new Video();
     newVideo.videoName = t.translationName;
     newVideo.videoTime = t.translationTime;
     newVideo.videoCategory = t.translationCategory;
     videoDb.videos.Add(newVideo);
     Save();
 }
예제 #2
0
        public ActionResult AddTranslation(HttpPostedFileBase file, Translation translation)
        {
            string contentData = string.Empty;
            // If the file is not empty, then we can read from the file and set contentData to that string.
            if (file != null)
            {
                using (StreamReader stream = new StreamReader(file.InputStream, Encoding.Default, true))
                {
                    contentData = System.Environment.NewLine + stream.ReadToEnd();
                }

                string extension = Path.GetExtension(file.FileName);

                // Just in case Javascript fails to recognize the file type.
                if (extension != ".srt")
                {
                    return View("WrongFileType");
                }
            }

            List<SelectListItem> languageList = new List<SelectListItem>();

            languageList.Add(new SelectListItem { Text = "Veldu Tungumál", Value = string.Empty });
            languageList.Add(new SelectListItem { Text = "Enska", Value = "Enska" });
            languageList.Add(new SelectListItem { Text = "Franska", Value = "Franska" });
            languageList.Add(new SelectListItem { Text = "Íslenska", Value = "Íslenska" });
            languageList.Add(new SelectListItem { Text = "Þýska", Value = "Þýska" });

            ViewData["translationLanguage"] = languageList;

            List<SelectListItem> categoryList = new List<SelectListItem>();

            categoryList.Add(new SelectListItem { Text = "Veldu Flokk", Value = string.Empty });
            categoryList.Add(new SelectListItem { Text = "Gaman", Value = "Gaman" });
            categoryList.Add(new SelectListItem { Text = "Hasar", Value = "Hasar" });
            categoryList.Add(new SelectListItem { Text = "Hryllings", Value = "Hryllings" });
            categoryList.Add(new SelectListItem { Text = "Rómantík", Value = "Rómantík" });
            categoryList.Add(new SelectListItem { Text = "Ævintýra", Value = "Ævintýra" });

            ViewData["translationCategory"] = categoryList;

            if(ModelState.IsValid)
            {
                string transName = translation.translationName;

                // If contentData is empty, then we don't want to set translationText as the uploaded file text.
                if (!String.IsNullOrEmpty(contentData))
                {
                    translation.translationText = translation.translationText + contentData;
                }

                IEnumerable<Video> videoNames = videoRepo.GetAllVideos().ToList();

                // Loop that checks if the new translation coming in has the same name as any video in the database.
                foreach(var item in videoNames)
                {
                    // If the video is already in the database, then we update the time and create new translation with the name of the video.
                    if(transName == item.videoName)
                    {
                        item.videoTime = translation.translationTime;
                        UpdateModel(item);
                        videoRepo.UpdateVideoTime(item);
                        videoRepo.Save();

                        translation.vID = item.ID;
                        translationRepo.Add(translation);

                        return RedirectToAction("/GetVideos");
                    }
                }

                int videoId = videoNames.Last().ID + 1;

                // Else create a new video and translation with the same name.
                videoRepo.AddVideo(translation);
                translation.vID = videoId;
                translationRepo.Add(translation);

                return RedirectToAction("/GetVideos");
            }

            return View(translation);
        }
예제 #3
0
 public void Add(Translation t)
 {
     translationDb.translations.Add(t);
     Save();
 }