private bool AddUpdateRepositoryLink(bool blResult, string strAction, RepositoryVo repoVo) { repoBo = new RepositoryBo(); try { blResult = (strAction.Equals(Constants.Add.ToString())) ? repoBo.AddRepositoryItem(repoVo, issueId) : repoBo.UpdateRepositoryItem(repoVo); } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { object[] objects = new object[1]; objects[0] = repoVo; PageException(objects, Ex, "ManageRepository.ascx:AddClick()"); } return(blResult); }
private bool AddFile(out bool blZeroBalance, out bool blFileSizeExceeded) { // If the upload type is file // We need to see if the adviser has a folder in Repository folder // Case 1: If not, then encode the adviser id and create a folder with the encoded id // then create a folder for the repository category within the encoded folder // then store the encoded adviserID + GUID + file name // Case 2: If folder exists, check if the category folder exists. // If not then, create a folder with the category code and store the file as done above. // If yes, then just store the file as done above. // Once this is done, store the info in the DB with the file path. strRepositoryPath = Server.MapPath(strRepositoryPath) + "\\advisor_" + advisorVo.advisorId; AdvisorBo advBo = new AdvisorBo(); repoBo = new RepositoryBo(); bool blResult = false; blZeroBalance = false; blFileSizeExceeded = false; try { // Reading File Upload Control if (radUploadRepoItem.UploadedFiles.Count != 0) { // Put this part under a transaction scope using (TransactionScope scope1 = new TransactionScope()) { UploadedFile file = radUploadRepoItem.UploadedFiles[0]; float fileSize = float.Parse(file.ContentLength.ToString()) / 1048576; // Converting bytes to MB // If space is there to upload file if (fStorageBalance >= fileSize) { if (fileSize <= 20) // If upload file size is less than 10 MB then upload { // Check if directory for advisor exists, and if not then create a new directoty if (!Directory.Exists(strRepositoryPath)) { Directory.CreateDirectory(strRepositoryPath); } strGuid = Guid.NewGuid().ToString(); string newFileName = SaveFileIntoServer(file, strGuid, strRepositoryPath); repoVo = new RepositoryVo(); repoVo.AdviserId = advisorVo.advisorId; repoVo.CategoryCode = ddlRCategory.SelectedValue; repoVo.Description = txtDescription.Text.Trim(); repoVo.HeadingText = txtHeadingText.Text.Trim(); repoVo.IsFile = true; repoVo.Link = newFileName; if (Request.QueryString["NCDProspect"] != null) { issueId = Convert.ToInt32(Request.QueryString["issueId"].ToString()); } blResult = repoBo.AddRepositoryItem(repoVo, issueId); if (blResult) { // Once the adding of repository is a success, then update the balance storage in advisor subscription table fStorageBalance = UpdateAdvisorStorageBalance(fileSize, 0, fStorageBalance); } } else { blFileSizeExceeded = true; } } else { blZeroBalance = true; } scope1.Complete(); // Commit the transaction scope if no errors } } else { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "alert('Please select a file to upload!');", true); } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { object[] objects = new object[2]; objects[0] = repoVo; objects[1] = repoBo; PageException(objects, Ex, "ManageRepository.ascx:AddClick()"); } return(blResult); }