Ejemplo n.º 1
0
 public void AddTranslation(Translation s)
 {
     m_db.Translations.Add(s);
     Save();
 }
Ejemplo n.º 2
0
 public void UpdateTranslation(Translation s)
 {
     Translation t = GetTranslationById(s.ID);
     if (t != null)
     {
         t.Title = s.Title;
         t.Text = s.Text;
         m_db.SaveChanges();
     }
 }
Ejemplo n.º 3
0
        public ActionResult LoadNewFile(HttpPostedFileBase Translation)
        {
            IEnumerable<Video> videos = videorepo.GetAllVideos();
            if (ModelState.IsValid)
            {
                if (Translation == null)    //ef enginn skrá er valinn
                {
                    ModelState.AddModelError("File", "Vinsamlegast veldu skrá");
                }
                else if (Translation.ContentLength > 0)
                {
                    string[] AllowedFileType = new string[] {".srt", ".txt"}; // leyfðar skráargerðir

                    if (!AllowedFileType.Contains(Translation.FileName.Substring(Translation.FileName.LastIndexOf('.')))) //ef skráin er af annarri týpu
                    {
                        ModelState.AddModelError("File", "Aðeins eru leyfðar skrár af gerðinni: " + string.Join(", ", AllowedFileType));
                    }
                    else
                    {
                        var FileName = Path.GetFileName(Translation.FileName);
                        var path = Path.Combine(Server.MapPath("~/Uploads/"), FileName);
                        Translation.SaveAs(path);
                        ModelState.Clear();
                        Translation item = new Translation();
                        StreamReader file = new StreamReader(path, Encoding.Default, true);
                        UpdateModel(item);
                        item.Text = file.ReadToEnd(); //tekur allan textann úr skjalinu og setur sem streng í gagnagrunn
                        string str = Translation.FileName;
                        str = str.Remove(str.Length - 4); //tekur seinustu 4 stafina af skráarnafninu (.srt/.txt)
                        item.Title = str;
                        item.LikeCount = 0;
                        item.DateLastEdited = DateTime.Now;
                        string Name = Request.Form["ValinMynd"]; //Tekur nafnið úr dropdowninu
                        file.Close();
                        videorepo.Save();
                        if(item.DeafCheck != null)//
                        {
                            item.DeafCheck = "Já";
                        }
                        else
                        {
                            item.DeafCheck = "Nei";
                        }
                        var choosenvid = videorepo.GetVideoByName(Name);
                        item.VideoID = choosenvid.ID;
                        choosenvid.TranslationCount += 1;
                        videorepo.Save();
                        repo.AddTranslation(item);
                        ViewBag.Message = ("Það Tókst að hlaða upp skránni");
                    }
                }
            }
            return View(videos);
        }