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 UpdateFile(out bool blZeroBalance, out bool blFileSizeExceeded) { repoBo = new RepositoryBo(); bool blResult = false; blZeroBalance = false; blFileSizeExceeded = false; try { // Reading File Upload Control int intUploadedFileCount = radUploadRepoItem.UploadedFiles.Count; if (intUploadedFileCount == 0) { // normal update repoVo.Description = txtDescription.Text.Trim(); repoVo.HeadingText = txtHeadingText.Text.Trim(); repoVo.Link = String.Empty; blResult = repoBo.UpdateRepositoryItem(repoVo); } else { // delete existing file and update new file // Put this part under a transaction scope using (TransactionScope scope2 = new TransactionScope()) { /* Perform transactional work here */ UploadedFile file = radUploadRepoItem.UploadedFiles[0]; float fileSize = float.Parse(file.ContentLength.ToString()) / 1048576; // Converting bytes to MB float oldFileSize = 0.0F; if (fileSize <= 2) { // If file size is less than 2 MB then upload // Get the Repository Path in solution string strFilePath = Server.MapPath(strRepositoryPath) + "\\advisor_" + advisorVo.advisorId + "\\" + repoVo.Link; float fStorageBalance = advisorVo.SubscriptionVo.StorageBalance; AdvisorBo advBo = new AdvisorBo(); // Delete file if it exists if (File.Exists(strFilePath)) { // Get the file size of the old file to calculate the balance storagee size FileInfo f = new FileInfo(strFilePath); long lSize = f.Length; oldFileSize = (lSize / (float)1048576); float flRemainingBal = fStorageBalance + oldFileSize; if (flRemainingBal >= fileSize) { File.Delete(strFilePath); } else { blZeroBalance = true; } } if (!blZeroBalance) { // Add new file strRepositoryPath = Server.MapPath(strRepositoryPath) + "\\advisor_" + advisorVo.advisorId; strGuid = Guid.NewGuid().ToString(); // Reading File Upload Control string newFileName = SaveFileIntoServer(file, strGuid, strRepositoryPath); // Update the DB with new details repoVo.Description = txtDescription.Text.Trim(); repoVo.HeadingText = txtHeadingText.Text.Trim(); repoVo.Link = newFileName; blResult = repoBo.UpdateRepositoryItem(repoVo); if (blResult) { // Once updating the repository is a success, then update the balance storage in advisor subscription table fStorageBalance = UpdateAdvisorStorageBalance(fileSize, oldFileSize, fStorageBalance); } } } else { blFileSizeExceeded = true; } scope2.Complete(); } } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { object[] objects = new object[2]; objects[0] = repoVo; objects[1] = repoBo; PageException(objects, Ex, "ManageRepository.ascx:UpdateClick()"); } return(blResult); }