protected void ibtnEdit_Click(object sender, EventArgs e) { if (IsChallengeFiles) { LinkButton ee = (LinkButton)sender; string documentId = (string)ee.CommandArgument; DocumentId = new Guid(documentId); challengeFileComponent = new ChallengeFileComponent(new Guid(documentId)); WizardFile.ActiveStepIndex = 1; txtFileName.Text = challengeFileComponent.ChallengeFile.ObjectName; lblExtension.Text = challengeFileComponent.ChallengeFile.ObjectExtension; var list = ListComponent.GetListPerCategory("ChallengeFile", Thread.CurrentThread.CurrentCulture.Name).FirstOrDefault(a => a.Label == challengeFileComponent.ChallengeFile.ObjectType); ddCategory.SelectedValue = list.Key; } else { LinkButton ee = (LinkButton)sender; string documentId = (string)ee.CommandArgument; DocumentId = new Guid(documentId); documentComponent = new DocumentComponent(new Guid(documentId)); WizardFile.ActiveStepIndex = 1; ddCategory.SelectedValue = documentComponent.Document.Category; txtTitle.Text = documentComponent.Document.Title; txtFileName.Text = documentComponent.Document.Name; lblExtension.Text = documentComponent.Document.FileType; txtDescription.Text = documentComponent.Document.Description; rdbScope.SelectedValue = documentComponent.Document.Scope; } UpdateFile.Visible = true; CreateFile.Visible = false; }
/// <summary> /// Update information of the file in the database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpdate_Click(object sender, EventArgs e) { try { if (IsChallengeFiles) { challengeFileComponent = new ChallengeFileComponent(DocumentId); challengeFileComponent.ChallengeFile.Updated = DateTime.Now; challengeFileComponent.ChallengeFile.ObjectName = ValidateSecurity.ValidateString(txtTitle.Text, false); challengeFileComponent.ChallengeFile.ObjectType = ddCategory.SelectedItem.Text; try { string pathServer = Server.MapPath(ddCategory.SelectedValue); string sourceFile = System.IO.Path.Combine(Server.MapPath(challengeFileComponent.ChallengeFile.ObjectLocation)); string destFile = System.IO.Path.Combine(pathServer, ValidateSecurity.ValidateString(txtFileName.Text, false) + ValidateSecurity.ValidateString(lblExtension.Text, false)); if (!Directory.Exists(pathServer)) { Directory.CreateDirectory(pathServer); } if (System.IO.File.Exists(sourceFile)) { if (!System.IO.File.Exists(destFile)) { System.IO.File.Move(sourceFile, destFile); } else { System.IO.File.Delete(destFile); System.IO.File.Move(sourceFile, destFile); } } challengeFileComponent.ChallengeFile.ObjectLocation = ddCategory.SelectedValue + ValidateSecurity.ValidateString(txtFileName.Text, false) + ValidateSecurity.ValidateString(lblExtension.Text, false); challengeFileComponent.Save(); } catch { } } else { documentComponent = new DocumentComponent(DocumentId); documentComponent.Document.Updated = DateTime.Now; documentComponent.Document.UploadedBy = UserId; documentComponent.Document.Version++; documentComponent.Document.Title = ValidateSecurity.ValidateString(txtTitle.Text, false); documentComponent.Document.Name = ValidateSecurity.ValidateString(txtFileName.Text, false); documentComponent.Document.Description = ValidateSecurity.ValidateString(txtDescription.Text, false); documentComponent.Document.Scope = rdbScope.SelectedValue; documentComponent.Document.Category = ddCategory.SelectedValue; documentComponent.Save(); } FillDataRepeater(); Count = 0; WizardFile.ActiveStepIndex = 0; } catch (Exception exc) { Exceptions. ProcessModuleLoadException( this, exc); } }
/// <summary> /// Delete document row of the database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDeleteUpdate_Click(object sender, EventArgs e) { if (IsChallengeFiles) { //Logical delete challengeFileComponent = new ChallengeFileComponent(DocumentId); challengeFileComponent.ChallengeFile.Updated = DateTime.Now; challengeFileComponent.ChallengeFile.Delete = true; challengeFileComponent.Save(); } else { //physical delete documentComponent = new DocumentComponent(DocumentId); documentComponent.Delete(); } FillDataRepeater(); WizardFile.ActiveStepIndex = 0; }
/// <summary> /// Save document in the server /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { try { string pathServerTemp = Server.MapPath("Portals/0/Images/Temp/"); string pathServerThumbImages = Server.MapPath("Portals/0/ModIma/ThumbImages/"); if (IsChallengeFiles) { if (string.IsNullOrEmpty(ValidateSecurity.ValidateString(txtTitle.Text, false))) { rgvtxtTitle.IsValid = false; return; } //Information of the document challengeFileComponent = new ChallengeFileComponent(Guid.NewGuid()); challengeFileComponent.ChallengeFile.Created = DateTime.Now; challengeFileComponent.ChallengeFile.Updated = challengeFileComponent.ChallengeFile.Created; challengeFileComponent.ChallengeFile.ObjectName = txtFileName.Text; challengeFileComponent.ChallengeFile.ObjectType = ddCategory.SelectedItem.Text; challengeFileComponent.ChallengeFile.Size = FileSize; challengeFileComponent.ChallengeFile.ObjectExtension = ExtensionName; challengeFileComponent.ChallengeFile.Language = Language; challengeFileComponent.ChallengeFile.ChallengeReferenceId = ChallengeReference; try { string pathServer = Server.MapPath(ddCategory.SelectedValue); string sourceFile = System.IO.Path.Combine(pathServerTemp, FileName + ExtensionName); string destFile = System.IO.Path.Combine(pathServer, ValidateSecurity.ValidateString(txtFileName.Text, false) + ValidateSecurity.ValidateString(lblExtension.Text, false)); if (!Directory.Exists(pathServer)) { Directory.CreateDirectory(pathServer); } if (System.IO.File.Exists(sourceFile)) { if (!System.IO.File.Exists(destFile)) { System.IO.File.Move(sourceFile, destFile); } else { System.IO.File.Delete(destFile); System.IO.File.Move(sourceFile, destFile); } } //Save document information in the database challengeFileComponent.ChallengeFile.ObjectLocation = ddCategory.SelectedValue + ValidateSecurity.ValidateString(txtFileName.Text, false) + ValidateSecurity.ValidateString(lblExtension.Text, false); challengeFileComponent.Save(); } catch { } } else { documentComponent = new DocumentComponent(Guid.NewGuid()); UserPropertyComponent user = new UserPropertyComponent(UserId); documentComponent.Document.Created = DateTime.Now; documentComponent.Document.CreatedBy = UserId; documentComponent.Document.Updated = documentComponent.Document.Created; documentComponent.Document.Views = 0; documentComponent.Document.Version = 1; documentComponent.Document.UploadedBy = user.UserProperty.UserId; documentComponent.Document.Author = string.Empty;// user.UserProperty.FirstName + " " + user.UserProperty.LastName; documentComponent.Document.Name = ValidateSecurity.ValidateString(txtFileName.Text, false); documentComponent.Document.Title = ValidateSecurity.ValidateString(txtTitle.Text, false); documentComponent.Document.FileType = ExtensionName; documentComponent.Document.Deleted = false; documentComponent.Document.Description = ValidateSecurity.ValidateString(txtDescription.Text, false); documentComponent.Document.Size = FileSize; documentComponent.Document.Permission = "0"; documentComponent.Document.Scope = rdbScope.SelectedValue; documentComponent.Document.Status = "published"; documentComponent.Document.Category = ddCategory.SelectedValue; documentComponent.Document.DocumentObject = Bytes; documentComponent.Document.ExternalReference = SolutionId; documentComponent.Document.Folder = Folder; //Save information of the document if (documentComponent.Save() < 0) { throw new Exception(); } if (ExtensionName.ToUpper() == ".PDF") { GhostscriptWrapper.GeneratePageThumb(pathServerTemp + FileName + ExtensionName, pathServerThumbImages + "pdf-" + documentComponent.Document.DocumentId.ToString() + ".jpg", 1, 150, 150, 300, 300); } } FillDataRepeater(); WizardFile.ActiveStepIndex = 0; } catch (Exception exc) { Exceptions. ProcessModuleLoadException( this, exc); } }
/// <summary> /// Load categories to the dropdownlist /// </summary> public void FillDataRepeater() { if (IsChallengeFiles) { List <NestedFile> nestedFiles = new List <NestedFile>(); List <List> list = ListComponent.GetListPerCategory("ChallengeFile", Thread.CurrentThread.CurrentCulture.Name).ToList(); List <ChallengeFile> fileList = null; DocumentsLoaded = 0; foreach (var item in list) { fileList = ChallengeFileComponent.GetFilesForChallenge(ChallengeReference, item.Label).ToList().Where(a => a.Delete == false || a.Delete == null).ToList(); if (fileList.Count > 0) { nestedFiles.Add(new NestedFile() { files = fileList, list = item }); DocumentsLoaded = DocumentsLoaded + fileList.Count; } } if (nestedFiles.Count > 0) { lblEmptyMessage.Visible = false; } else { lblEmptyMessage.Visible = true; } rCategory.DataSource = nestedFiles; rCategory.DataBind(); } else { List <NestedDocument> nestedDocuments = new List <NestedDocument>(); List <List> list = ListComponent.GetListPerCategory("FileCategory", Thread.CurrentThread.CurrentCulture.Name).ToList(); List <Document> documentList = null; DocumentsLoaded = 0; foreach (var item in list) { if (Folders != null) { foreach (var item2 in Folders) { documentList = DocumentComponent.GetDocuments(SolutionId, item.Key, item2); if (documentList.Count > 0) { nestedDocuments.Add(new NestedDocument() { documents = documentList, list = item }); DocumentsLoaded = DocumentsLoaded + documentList.Count; } } } else { documentList = DocumentComponent.GetDocuments(SolutionId, item.Key, Folder); if (documentList.Count > 0) { nestedDocuments.Add(new NestedDocument() { documents = documentList, list = item }); DocumentsLoaded = DocumentsLoaded + documentList.Count; } } } if (nestedDocuments.Count > 0) { lblEmptyMessage.Visible = false; } else { lblEmptyMessage.Visible = true; } rCategory.DataSource = nestedDocuments; rCategory.DataBind(); } }