public void IncreaseDownloadCount(FileResource fileResource) { fileResource.DownloadCount++; this._commonDao.UpdateObject(fileResource); }
public void UpdateFileResource(FileResource fileResource) { this._contentItemService.Save(fileResource); }
public virtual void DeleteFileResource(FileResource FileResource) { // Delete physical file. this._fileService.DeleteFile(FileResource.PhysicalFilePath); // Delete meta info. this._contentItemService.Delete(FileResource); }
private void BindCategoriesAndRoles(FileResource fileResource, string categoryids, int[] roleIds) { // TODO: handle more generic (Binder? base Controller?) fileResource.Categories.Clear(); if (!String.IsNullOrEmpty(categoryids)) { foreach (string categoryIdString in categoryids.Split(',')) { fileResource.Categories.Add(this._categoryService.GetCategoryById(Convert.ToInt32(categoryIdString))); } } // TODO: handle Roles etc. more generic. fileResource.ContentItemPermissions.Clear(); if (roleIds != null) { var roles = this._userService.GetRolesByIds(roleIds); foreach (Role role in roles) { fileResource.ContentItemPermissions.Add(new ContentItemPermission { ContentItem = fileResource, Role = role, ViewAllowed = true }); } } }
public virtual void SaveFileResource(FileResource fileResource, Stream fileContent) { // Save physical file. fileResource.PhysicalFilePath = IOUtil.EnsureUniqueFilePath(fileResource.PhysicalFilePath); this._fileService.WriteFile(fileResource.PhysicalFilePath, fileContent); // Save meta info this._contentItemService.Save(fileResource); }
public virtual void SaveFileInfo(FileResource file) { //When saving meta-information use the ContentItem service _contentItemService.Save(file); }
/// <summary> /// Show form for new file. /// </summary> /// <returns></returns> public ActionResult New() { ViewData["Roles"] = this._userService.GetAllRolesBySite(CuyahogaContext.CurrentSite); FileResource fileResource = new FileResource(); // For new items, inherit the permissions of the section foreach (SectionPermission sectionPermission in CurrentSection.SectionPermissions) { fileResource.ContentItemPermissions.Add(new ContentItemPermission { ContentItem = fileResource, Role = sectionPermission.Role, ViewAllowed = sectionPermission.ViewAllowed }); } return View("New", GetModuleAdminViewModel(fileResource)); }
public virtual void SaveFile(FileResource file, System.IO.Stream fileContents) { // Save physical file. string fullFilePath = file.PhysicalFilePath + file.FileName; this._fileService.WriteFile(fullFilePath, fileContents); // Save meta-information. SaveFileInfo(file); }
/// <summary> /// Increase the number of downloads for the given file. /// </summary> /// <param name="file"></param> public virtual void IncreaseNrOfDownloads(FileResource file) { //If a person who is not authenticated downloads //how do we save the update when ModifiedBy is required? //Will only increment for authenticated users if (HttpContext.Current.User.Identity.IsAuthenticated) { file.DownloadCount++; file.ModifiedBy = HttpContext.Current.User.Identity as User; file.ModifiedAt = DateTime.Now; SaveFileInfo(file); } }
/// <summary> /// Get the a file as stream. /// </summary> /// <returns></returns> public System.IO.Stream GetFileAsStream(FileResource file) { User currentUser = HttpContext.Current.User as User; bool viewAllow = false; foreach (Role cur in currentUser.Roles) { viewAllow = file.ViewRoles.Contains(cur) ? true : false; } if (viewAllow) { string physicalFilePath = System.IO.Path.Combine(this.FileDir, file.PhysicalFilePath); if (System.IO.File.Exists(physicalFilePath)) { return this._fileService.ReadFile(physicalFilePath); } else { throw new System.IO.FileNotFoundException("File not found", physicalFilePath); } } else { throw new AccessForbiddenException("The current user has no permission to download the file."); } }
public virtual void DeleteFile(FileResource file) { // Delete physical file. //string physicalFilePath = file.PhysicalFilePath; string physicalFilePath = System.IO.Path.Combine(file.PhysicalFilePath, file.FileName); this._fileService.DeleteFile(physicalFilePath); // Delete meta information. ISession session = this._sessionManager.OpenSession(); session.Delete(file); }
private void Page_Load(object sender, System.EventArgs e) { _userService = IoC.Resolve<IUserService>(); // The base page has already created the module, we only have to cast it here to the right type. this._downloadsModule = base.Module as DownloadsModule; this._fileId = Int32.Parse(Request.QueryString["FileId"]); if (this._fileId > 0) { this._file = this._downloadsModule.GetFileById(this._fileId); if (! this.IsPostBack) { BindFile(); } this.btnDelete.Visible = true; this.btnDelete.Attributes.Add("onclick", "return confirm('Are you sure?');"); } else { // It is possible that a new file is already uploaded and in the database. The // tempFileId parameter in the viewstate should indicate this. if (ViewState["tempFileId"] != null) { int tempFileId = int.Parse(ViewState["tempFileId"].ToString()); this._file = this._downloadsModule.GetFileById(tempFileId); } else { // New file. this._file = new FileResource(); // Copy roles that have view rights from parent section. foreach (Permission permission in this._downloadsModule.Section.SectionPermissions) { this._file.ContentItemPermissions.Add(new ContentItemPermission { ContentItem = this._file, Role = permission.Role, ViewAllowed = permission.ViewAllowed }); } this.calDatePublished.SelectedDate = DateTime.Now; } this.btnDelete.Visible = false; } if (! this.IsPostBack) { BindRoles(); } }