コード例 #1
0
        public static void LogUserAction(User user, AuditUserAction auditUserAction, string notes)
        {
            AuditUserHistory auh = AuditUserHistory.New();

            auh.SessionId         = BusinessHelper.GetCurrentSessionId();
            auh.IpAddress         = BusinessHelper.GetCurrentIpAddress();
            auh.AuditUserActionId = Convert.ToInt32(auditUserAction);
            auh.UserId            = user.UserId.GetValueOrDefault();
            auh.Notes             = notes;
            auh.Date = DateTime.Now;
            AuditUserHistory.Update(auh);

            m_Logger.InfoFormat("LogUserAction - User: {0}, Action: {1}, Notes: {2}", user.FullName, auditUserAction, notes);
        }
コード例 #2
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            Brand brand = Brand.Empty;

            if (WebUtils.GetIntRequestParam("BrandId", 0) != 0)
            {
                brand = Brand.Get(WebUtils.GetIntRequestParam("BrandId", 0));
            }

            if (brand.IsNull)
            {
                brand = Brand.New();
            }

            brand.Name                         = FullBrandNameTextBox.Text.Trim();
            brand.ShortName                    = ShortBrandNameTextBox.Text.Trim();
            brand.ApplicationName              = ApplicationNameTextBox.Text.Trim();
            brand.OrganisationName             = OrganisationNameTextBox.Text.Trim();
            brand.WebsiteUrl                   = WebsiteUrlTextBox.Text.Trim();
            brand.EmailFrom                    = EmailFromTextBox.Text.Trim();
            brand.IsBrandSelectionAllowed      = AllowBrandSelectionDuringRegistrationCheckBox.Checked;
            brand.DisablePoweredByLogo         = (DisabledPoweredByFooterCheckBox != null) ? DisabledPoweredByFooterCheckBox.Checked : false;
            brand.LoginPageUpperCopy           = LoginPageUpperCopyTextBox.Text.Trim();
            brand.LoginPageLowerCopy           = LoginPageLowerCopyTextBox.Text.Trim();
            brand.DefaultUsageRestrictionsCopy = DefaultUsageRestrictionsCopyTextBox.Text.Trim();
            brand.MyAccountCopy                = MyAccountCopyTextBox.Text.Trim();
            brand.AdminCopy                    = AdminCopyTextBox.Text.Trim();
            brand.TermsConditionsCopy          = TermsConditionsCopyTextBox.Text.Trim();
            brand.PrivacyPolicyCopy            = PrivacyPolicyCopyTextBox.Text.Trim();
            brand.DirectDownloadEnabled        = EnableDirectDownloadCheckBox.Checked;

            BinaryFile filePack       = new BinaryFile(BrandFilePackUpload.PostedFile);
            BinaryFile watermarkImage = new BinaryFile(PreviewWatermarkImageUpload.PostedFile);

            try
            {
                if (!IsBrandFolderWriteable())
                {
                    MessageLabel1.SetErrorMessage("Error saving brand", "Brand folder not writeable - please change the permissions in the brands folder");
                    return;
                }

                // Temp flag to check if brand is new
                // Do not inline. This will be cleared when brand is saved.
                bool isNew = brand.IsNew;

                // Validate and save the brand info to the database
                BrandManager.Save(brand, filePack, watermarkImage);

                // Update log
                AuditUserAction action = (isNew) ? AuditUserAction.AddBrand : AuditUserAction.ModifyBrand;
                AuditLogManager.LogUserAction(CurrentUser, action, string.Format("Saved brand: {0}. Brand ID: {1}", brand.Name, brand.BrandId));

                // Get the relative brand folder
                string brandFolderPath = string.Format("~/Brands/Brand_{0}/", brand.BrandId);

                // Convert brand folder to absolute path
                string absBrandFolderPath = Server.MapPath(brandFolderPath);

                // Create the brand folder if it doesn't exist
                if (!Directory.Exists(absBrandFolderPath))
                {
                    Directory.CreateDirectory(absBrandFolderPath);
                    m_Logger.DebugFormat("Created brand folder path: {0}", absBrandFolderPath);
                }

                // Ensure specific brand folder is writeable
                string tmpPath = Path.Combine(absBrandFolderPath, Guid.NewGuid() + ".tmp");

                try
                {
                    File.WriteAllText(tmpPath, "Folder is writeable");
                    File.Delete(tmpPath);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Error checking if brand folder is writeable: " + ex.Message);
                    MessageLabel1.SetErrorMessage(string.Format("Brand folder not writeable (~/Brands/Brand_{0}/) - please change the permissions in the brands folder", brand.BrandId));
                    return;
                }

                // Save watermark
                if (!watermarkImage.IsEmpty)
                {
                    // Get any old watermark files
                    var files = (from f in Directory.GetFiles(absBrandFolderPath)
                                 where (Path.GetFileName(f) ?? string.Empty).ToLower().StartsWith("watermark")
                                 select f);

                    // Delete them
                    foreach (string file in files)
                    {
                        File.Delete(file);
                    }

                    // Save new watermark
                    string watermarkPath = Path.Combine(absBrandFolderPath, "watermark." + watermarkImage.FileExtension);
                    watermarkImage.SaveAs(watermarkPath);
                }

                if (!filePack.IsEmpty)
                {
                    // Save the zip file to disk
                    string tempZipPath = Path.GetTempFileName() + ".zip";
                    filePack.SaveAs(tempZipPath);

                    // Extract the uploaded zip into the brand folder
                    FastZip fz = new FastZip();
                    fz.ExtractZip(tempZipPath, absBrandFolderPath, FastZip.Overwrite.Always, null, string.Empty, string.Empty, true);

                    // Delete the temp zip file
                    File.Delete(tempZipPath);
                }

                if (filePack.IsEmpty && isNew)
                {
                    Brand  masterBrand       = WebsiteBrandManager.GetMasterBrand();
                    string masterBrandFolder = Server.MapPath(string.Format("~/Brands/Brand_{0}/", masterBrand.BrandId));

                    try
                    {
                        CopyFolder(masterBrandFolder, absBrandFolderPath);
                        m_Logger.DebugFormat("Copied folder {0} to {1}", masterBrandFolder, absBrandFolderPath);
                    }
                    catch (Exception ex)
                    {
                        m_Logger.Error(string.Format("Error copying Brand folder from master brand to new brand: {0}. Error: {1}", brand.Name, ex.Message), ex);
                    }
                }

                Response.Redirect("ManageBrands.aspx?message=BrandSaved", false);
            }
            catch (InvalidBrandException ibex)
            {
                MessageLabel1.SetErrorMessage("Error saving brand", ibex.Errors);
            }
            catch (Exception ex)
            {
                MessageLabel1.SetErrorMessage("An unknown error occurred while saving brand", ex.Message);
                m_Logger.ErrorFormat("Error saving brand: " + ex.Message, ex);
                ExceptionHandler.HandleException(ex, "Error saving brand");
            }
        }