Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ID,Title,DepartmentID,Description,Contents")] FileViewModel fileVM)
        {
            if (ModelState.IsValid)
            {
                UserFile file = new UserFile()
                {
                    Title            = fileVM.Title,
                    Description      = fileVM.Description,
                    MimeType         = fileVM.Contents.ContentType,
                    Department       = repo.Department(fileVM.DepartmentID),
                    OriginalFilename = fileVM.Contents.FileName,
                    Content          = null
                };

                BinaryReader binaryReader = new BinaryReader(fileVM.Contents.InputStream);
                file.Content = binaryReader.ReadBytes(fileVM.Contents.ContentLength);
                repo.AddFile(file);

                return(RedirectToAction("Index"));
            }

            ViewBag.Departments = repo.GetManagedDepartmentsByUserName(User.Identity.Name).Select(d => new SelectListItem()
            {
                Text = d.Name, Value = d.ID.ToString()
            });

            return(View(fileVM));
        }