Пример #1
0
        public ActionResult Create(FileUpload item)
        {
            if (ModelState.IsValid)
            {
               //Reads the .srt file content into a string
                var b = new System.IO.BinaryReader(item.File.InputStream);
                byte[] binData = b.ReadBytes((int)item.File.InputStream.Length);
                string result = System.Text.Encoding.UTF8.GetString(binData);

                System.Diagnostics.Debug.Write(result);

                //Constructor for srtFiles
                var entityObj = new srtFiles
                {
                    Title = item.FileTitle,
                    Content = result,
                    Date = DateTime.Now,
                    Category = item.FileCategory,
                    Genre = item.FileGenre,
                    Status = item.FileStatus,
                    Language = item.FileLanguage

                };
                //Saves the object into the database
                repo.AddFile(entityObj);
                repo.Save();
                return RedirectToAction("SubtitleMade");
            }
            else
            {
                //if the model is not valid it loads the view again
                AddLanguages();
                AddCategories();
                AddGenre();
                AddStatus();
                return View(item);
            }
        }
Пример #2
0
        public ActionResult CreateRequest(FileUpload item)
        {
            if (ModelState.IsValid)
            {
                var b = new System.IO.BinaryReader(item.File.InputStream);
                byte[] binData = b.ReadBytes((int)item.File.InputStream.Length);
                string result = System.Text.Encoding.UTF8.GetString(binData);

                System.Diagnostics.Debug.Write(result);

                var entityObj = new srtFiles
                {
                    Title = item.FileTitle,
                    Content = result,
                    Date = DateTime.Now,
                    Category = item.FileCategory,
                    Genre = item.FileGenre,
                    Status = item.FileStatus,
                    Language = item.FileLanguage

                };

                repo.AddFile(entityObj);
                repo.Save();
                return RedirectToAction("RequestMade");
            }
            else
            {
                AddLanguages();
                AddCategories();
                AddGenre();
                AddStatusRequest();
                return View(item);
            }
        }