public ActionResult Edit(int id, File file, HttpPostedFileBase uploadedFile) { var fileToEdit = _repositoryFactory.FileRepository.GetNullableById(id); if (fileToEdit == null) { Message = "Unable to locate file."; return(RedirectToAction("Index", "Seminar")); } ModelState.Clear(); AutoMapper.Mapper.Map(file, fileToEdit); if (uploadedFile != null) { var reader = new BinaryReader(uploadedFile.InputStream); var data = reader.ReadBytes(uploadedFile.ContentLength); fileToEdit.Contents = data; fileToEdit.ContentType = uploadedFile.ContentType; fileToEdit.FileName = uploadedFile.FileName; } fileToEdit.TransferValidationMessagesTo(ModelState); if (ModelState.IsValid) { _repositoryFactory.FileRepository.EnsurePersistent(fileToEdit); Message = "File has been updated."; return(RedirectToAction("Edit", "Seminar", new { id = fileToEdit.Seminar.Id })); } return(View(FileViewModel.Create(_repositoryFactory, fileToEdit.Seminar.Id, fileToEdit))); }
public ActionResult Create(int seminarId, File file, HttpPostedFileBase uploadedFile) { ModelState.Clear(); file.Seminar = SiteService.GetLatestSeminar(Site); if (uploadedFile != null) { var reader = new BinaryReader(uploadedFile.InputStream); var data = reader.ReadBytes(uploadedFile.ContentLength); file.Contents = data; file.ContentType = uploadedFile.ContentType; file.FileName = uploadedFile.FileName; } file.TransferValidationMessagesTo(ModelState); if (ModelState.IsValid) { _repositoryFactory.FileRepository.EnsurePersistent(file); Message = "File has been saved to seminar"; return(RedirectToAction("Edit", "Seminar", new { id = seminarId })); } return(View(FileViewModel.Create(_repositoryFactory, seminarId, file))); }
public async Task <ActionResult> FileProperties(string tabId, int parentId, string id, string successfulActionCode) { var file = ContentFolderService.GetFile(parentId, id); var model = FileViewModel.Create(file, tabId, parentId, false); model.SuccesfulActionCode = successfulActionCode; return(await JsonHtml("FileProperties", model)); }
public ActionResult FileProperties(string tabId, int parentId, string id, string successfulActionCode) { var file = SiteFolderService.GetFile(parentId, id); var model = FileViewModel.Create(file, tabId, parentId, true); model.SuccesfulActionCode = successfulActionCode; return(JsonHtml("FileProperties", model)); }
public ActionResult Edit(int id) { var file = _repositoryFactory.FileRepository.GetNullableById(id); if (file == null) { Message = "Unable to locate file."; return(RedirectToAction("Index", "Seminar")); } return(View(FileViewModel.Create(_repositoryFactory, file.Seminar.Id, file))); }
public async Task <ActionResult> FileProperties(string tabId, int parentId, string id, IFormCollection collection) { var file = ContentFolderService.GetFile(parentId, id); var model = FileViewModel.Create(file, tabId, parentId, false); await TryUpdateModelAsync(model); if (ModelState.IsValid) { ContentFolderService.SaveFile(model.File); return(Redirect("FileProperties", new { tabId, parentId, id = model.Id, successfulActionCode = ActionCode.UpdateContentFile })); } return(await JsonHtml("FileProperties", model)); }
public ActionResult FileProperties(string tabId, int parentId, string id, FormCollection collection) { var file = SiteFolderService.GetFile(parentId, id); var model = FileViewModel.Create(file, tabId, parentId, true); TryUpdateModel(model); model.Validate(ModelState); if (ModelState.IsValid) { SiteFolderService.SaveFile(model.File); return(Redirect("FileProperties", new { tabId, parentId, id = model.Id, successfulActionCode = ActionCode.UpdateSiteFile })); } return(JsonHtml("FileProperties", model)); }
public ActionResult GetFiles(string messageIds) { var user = _repository.ApplicationUserRepository.GetUserById(User.Identity.GetUserId()); if (user == null) { return(HttpNotFound()); } var ids = messageIds.Split('#'); var model = new List <FileViewModel>(); foreach (var id in ids) { try { var message = _repository.MessengerRepository.GetMessage(user.Id, Convert.ToInt32(id)); if (message == null) { continue; } model.Add(FileViewModel.Create(message)); } catch { // ignored } } if (model.Any()) { return(PartialView("~/Views/Messenger/File.cshtml", model)); } return(HttpNotFound()); }
public ActionResult Create(int seminarId) { return(View(FileViewModel.Create(_repositoryFactory, seminarId))); }