Пример #1
0
        public ActionResult Edit(File file)
        {
            if (ModelState.IsValid)
            {
                //make sure the edited file has the same user profile assigned to it
                file.User = _usersRepository.GetUserProfileByName(User.Identity.Name.ToLower());
                file.Data = DateTime.Now;
                //save the changes
                _filesRepository.EditFile(file);

                return(RedirectToAction("Index"));
            }
            return(View(file));
        }
Пример #2
0
        public ActionResult Upload(HttpPostedFileBase fisier)
        {
            if (fisier != null && fisier.ContentLength > 0)
            {
                var userProfile = _usersRepository.GetUserProfileByName(User.Identity.Name.ToLower());
                var newFile     = new File
                {
                    Data        = DateTime.Now,
                    Description = fisier.FileName,
                    FileName    = fisier.FileName,
                    FileType    = fisier.ContentType,
                    UserId      = userProfile.UserId
                };

                using (var binaryReader = new BinaryReader(fisier.InputStream))
                {
                    newFile.FileContent = binaryReader.ReadBytes(fisier.ContentLength);
                }

                _filesRepository.InsertFile(newFile);
            }
            return(RedirectToAction("Index"));
        }