connection string encrypt decrypt on web.config

Encrypt 

  1. Run Command Prompt as Administrator
  2. Go to C:\Windows\Microsoft.NET\Framework\v4.0.30319 
  3. cdC:\Windows\Microsoft.NET\Framework\v4.0.30319
  4. Enter this,
ASPNET_REGIIS -pef "connectionStrings" "D:\development\Divercybkup\Diversey_93212\Sana.Commerce.Startersite"


Decrypt


  1. Run Command Prompt as Administrator
  2. Go to C:\Windows\Microsoft.NET\Framework\v4.0.30319
  3. cdC:\Windows\Microsoft.NET\Framework\v4.0.30319
  4. Enter this,
ASPNET_REGIIS -pdf "connectionStrings" "D:\development\Divercybkup\Diversey_93212\Sana.Commerce.Startersite"



connectionStrings,securityKeys,machineKey

ASPNET_REGIIS -pdf "connectionStrings" "E:\New folder\beta\Frontend"
ASPNET_REGIIS -pdf "securityKeys" "E:\New folder\beta\Frontend"
ASPNET_REGIIS -pdf "machineKey" "E:\New folder\beta\Frontend"


ASPNET_REGIIS -pdf "connectionStrings" "E:\New folder\live\Frontend"
ASPNET_REGIIS -pdf "securityKeys" "E:\New folder\live\Frontend"
ASPNET_REGIIS -pdf "machineKey" "E:\New folder\live\Frontend"

How to do a Migration Beat to Live,


Example Video on Migration 
https://web.microsoftstream.com/video/8f2f19dd-2351-4057-b50d-082c0bb8675a


1. Create a ticket request to do the DB migration from the Host Team.

Use the following link to create Tickets.

Already Created example
Anajet: https://sanacommerce.visualstudio.com/Sana%20Hosting/_workitems/edit/60840
Coulisse: https://sanacommerce.visualstudio.com/Sana%20Hosting/_workitems/edit/88912/

2.Copy Beta data to LiveUpgrade(newly created)
2.Copy Lived data to LiveUpgrade(newly created)
Tables,
2.1 WebsiteDomains Table
eg : Copy WebsiteDomains table details to AnaJetLive(Live) to AnaJetLiveUpgraded(newly-created DB). 

2.2 Setting Table
(need to remove connection settings otherwise it will give an error and will not load the project)
Remove Key=Connection from LiveUpgrade.



  
  1. Come to the server, takes full backup of Live DB
                        for safety, create a zip file of this backup.

  1. Change web.config file with New Database.

4.1 Do the decrypt the web.config file
      > cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
      >aspnet_regiis -pdf "connectionStrings" "C:\Sana Commerce\Projects\BetaSanaStore\Frontend"

4.2 Before updating db name double-check, the site is working after decrypting the web.config.
4.3 Update web config with new DB Name.
4.4 Restart app pool

  1. Duplicate the Sana Admin page and go to user Manager >Edit Live Backoffice user (Keep it) 

    6.  After change the Database name, the Site's Backoffice Account also change,
         (because we created the new DB as a copy of the Beta database).

          6.1  so go to the back-office and log with Beta Backoffice credentials.

   7. Change password back to Live Backoffice credentials.
        7.1 go Admin section > User management > change to Live credentials .
        7.2 Check the Permission are same as before with user manager  page duplicated earlier.
  
   8.  Then Log out and login with Live credentials.

   9. fill ERP details from starter site  >ERP web  service.
       9.1 Test the connection.

  10. Then need to run tasks



for live set task server to true
<add key="TaskServer" value="true" />
       
10.1 if web service not set I by Database:- 'Servers' table, set Live and Liveupdate look same.
Refresh both caches (ERP, site)

        run General , Customer ,Product



  1. Install Addons.

Go to Live db > Settings table > check any Extensions installed , Delete  them.
Eg: Extension_AuthorizeNet, Extension_FedEx.

  1. Copy the Addon settings from Beta to PreLive eg : Authorize.net ,FedEX.
  2. Check Payment Methods show properly if have.
  3. Check Shipping Method ""

  1. Go to Website view  and check missing images ,
Product images no need to copy, but if some images are used in same pages , then add

  1. If all looks fine Change DB names, to change  as shared sana Admin on DB
  2. eg : AnajetLive--> AnajetLive_old
  3. Eg : AnajetUpgrade --> AnajetLive


Then do Smoke Test.


CUSTOMER REGISTRATION FORM

 Borsig rqs v1.8
3.8.          Customer Registration form

Change new account form 






create new validation attribute : set a max date for datepicker

set a max date for datepicker
Divercy  LookupPeriodDateValidationAttribute,DisableDateValidationAttribute


1. Create a new ValidationAttribute class
eg : LookupPeriodDateValidationAttribute,DisableDateValidationAttribute
or search MustBeTrueAttribute on sana ,


public class LookupPeriodDateValidationAttribute : ValidationAttribute, IClientValidatable
    { 
        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            var rule = new ModelClientValidationRule();
            rule.ValidationType = "lookupperiod";
            rule.ErrorMessage = FormatErrorMessage(metadata.GetDisplayName());         
            return new[] { rule };
        }
    }




1.1
IsValid() //  this method will hit when submitting the order.

public override bool IsValid(object value)
        {
            if (value == null)
                return true;

            if (value is Date)
            {
                var date = (Date)value;
                return date >= Date.Now;
            }
            else if (value is Date?)
            {
                var date = (Date?)value;
                return date.Value >= Date.Now;
            }
            else if (value is DateTime)
            {
                var date = (DateTime)value;
                return date >= DateTime.Now;
            }
            else if (value is DateTime?)
            {
                var date = (DateTime?)value;
                return date.Value >= DateTime.Now;
            }
            else
            {
                return false;
            }         
        }


---

2. update sana.validate.unobtrusive.js

 $.validator.unobtrusive.adapters.add('lookupperiod', [], function (options) {     
        options.rules['lookupperiod'] = {};
        if (options.message) {
            options.messages['lookupperiod'] = options.message;         
        }
    });




3. update sana.validate.js

$.validator.addMethod('lookupperiod', function (value, element, params) {

        if (!value) {
            return true;
        }

        var dateFormat = $(element).datepicker('option', 'dateFormat');
        try {
            var date = $.datepicker.parseDate(dateFormat, value);
            var todayDate = (new Date()).setHours(0, 0, 0, 0);
            return date >= todayDate;
        }
        catch (e) {
            return false;
        }
    });



4. Apply the Attribute to the field
eg: 

 [LookupPeriodDateValidation(ErrorMessageResourceName = SanaTextKeys.InvalidField)]
 [DisableDateValidation(ErrorMessageResourceName = SanaTextKeys.InvalidField)]
 public override Date? DeliveryDate { get; set; }



Add attribute to button eg disable

 @Sana.SubmitButton("Submit", "btn btn-big btnCreateNewAcc", htmlAttributes: new { @disabled = "disabled" })

Checkbox must true

[MustBeTrue(ErrorMessage = "Register_IsAgreedMessage")]
        [Display(Name = "Register_IsConfirm")]
        [Required]
        [UIHint("Register_IsConfirm")]
        public virtual bool IsAgreed { get; set; }

How to Create New Mail Template


1. Issue :Ravensburger  [49417] 3.5. ORDER FAILURE – E-MAIL

2. Issue: Versalert 3.7. PRODUCT LIST/DETAIL PAGE – REQUEST TO ADD/DELETE ITEM FROM FIXED ORDER LIST


Ravensburger  [49417] 3.5. ORDER FAILURE – E-MAIL
1. create a Template Name


public virtual string GetOrderFailedMailTemplateName()
 {
    return "OrderFail";
 }



2.Get Email Address and Create Order Mail Method on ExtendedCheckoutApi.






/// <summary>
        /// [49417] 3.5. ORDER FAILURE – E-MAIL
        /// This method will send the Order Failed Mail
        /// </summary>
        /// <param name="order">order</param>
        /// <param name="basket">basket</param>
        /// <param name="errorMessage">error message</param>
        private void SendFailedOrderMail(IOrder order,IBasket basket, string errorMessage)
        {
            //Set Order Total values from Basket Values.
            SetOrderTotalPrice(order, basket);
 
            //Get Admin Setting Order Failed Email address 
            var settings = (CommerceFrameworkBase.ShopSettings.GetSettings(SettingsKeys.General));
            var ws = ObjectFactory.Create<Sana.Commerce.Shop.IWebsiteSettings>();
            ws.Initialize(settings);
            var list = ((ExtendedWebsiteSettings)ws).OrderFailedEmailAddress.Split(';');
 
            if (list != null)
            {
                List<MailAddress> addressList = new List<MailAddress>();
                foreach (var item in list)
                {
                    if (!string.IsNullOrEmpty(item))
                    {
                        addressList.Add(new MailAddress(item));
                    }
                }
                ((Sana.Commerce.Order.Order)order).OrderFailedErrorMessage = errorMessage;
 
                var templateName = GetOrderFailedMailTemplateName();
                var mail = ServiceManager.GetInstance<ExtendedOrderConfirmationHelper>().GetOrderFailureMail(templateName, order, null, addressList);
                ShopApi.Mail.Send(mail);
 
            }
        }



3.
ExtendedOrderConfirmationHelper > GetOrderFailureMail

Email creation has done from here.(set order template, Replace tags,BCC,CC, receipts )


public virtual MailMessage GetOrderFailureMail(string templateName, IOrder order, NameValueCollection additionalReplaceTags = nullIList<MailAddress> recipients = null)
        {
            var shopContext = ShopContext.GetCurrent();
            var settings = shopContext.Settings;
 
            var fromAddress = new MailAddress(settings.FromEmailAddress);
            var replaceTags = GetFailOrderReplaceTags(shopContext, order);
            if (additionalReplaceTags != null)
            {
                additionalReplaceTags.AllKeys.Each(tagName => replaceTags.Add(tagName, additionalReplaceTags[tagName]));
            }
 
            var additionalData = new Dictionary<stringobject>();
            additionalData.Add("OrderDetails", CreateOrderDetailsModel(shopContext, order));
 
            if (recipients == null)
            {
                recipients = GetEmailAddresses(shopContext, order);
            }
 
            var mail = ShopApi.Mail.Render(fromAddress, recipients, templateName, replaceTags, additionalData);
            if (settings.BccEmailAddresses != null)
            {
                settings.BccEmailAddresses.Each(bcc => mail.Bcc.Add(new MailAddress(bcc)));
            }
            return mail;
        }


4.
ExtendedOrderConfirmationHelper > GetReplaceTags()


protected virtual NameValueCollection GetFailOrderReplaceTags(ShopContext shopContext, IOrder order)
        {
            var currentUserAccount = CommerceFramework.ShopAccounts.GetShopAccount(shopContext.ShopAccount.Id, true);
            var customer = CommerceFrameworkBase.Customers.GetCustomer(shopContext.CommerceContext.AccountId);
 
            var replaceTags = base.GetReplaceTags(shopContext, order);
 
            replaceTags.Add("CUSTOMER_NAME_LABEL"CommerceFrameworkBase.SanaTexts.GetSanaText("CustomerNameLabel""Customer Name"));
            replaceTags.Add("CUSTOMER_ID_LABEL"CommerceFrameworkBase.SanaTexts.GetSanaText("CustomerIdLabel""Customer Id"));
            replaceTags.Add("SHOPACCOUNT_EMAIL_LABEL"CommerceFrameworkBase.SanaTexts.GetSanaText("ShopAccountEmailLabel""Shop Account Email"));
            replaceTags.Add("SHOPACCOUNT_NAME_LABEL"CommerceFrameworkBase.SanaTexts.GetSanaText("ShopAccountNameLabel""Shop Account"));
 
            replaceTags.Add("CUSTOMER_NAME", customer.Name);
            replaceTags.Add("CUSTOMER_ID", customer.Id);
            replaceTags.Add("SHOPACCOUNT_EMAIL", shopContext.ShopAccount.Email);
            replaceTags.Add("ORDER_ERROR_MESSAGE", ((Sana.Commerce.Order.Order)order).OrderFailedErrorMessage);
            return replaceTags;
        }


5. Add new email Template
~/Views/Default/MailTemplates/OrderFail.cshtml

6.Update Language packs Mail templates
\Ravensburger\@data\packages\LanguagePack_de-DE.9.3.5.0\MailTemplates




2. Versalert 3.7. PRODUCT LIST/DETAIL PAGE – REQUEST TO ADD/DELETE ITEM FROM FIXED ORDER LIST

ExtendedProductListController > SendRequestToAddToFixedOrderList


3.Bachofen : QuoteEmailAddress





If Need to Create Admin setting also :- search :
Add Admin Setting , Add new Email Section to Admin

add field to ExtendedStoreInfoModel ,ExtendedWebsiteSettings


Get Data to View without using passing through model , Pass Data to View


You can access get Value to view from Managers

 Eg : Order Manager

Project : Divercy :- 
page :- _MonthlyBuddgetAllowance.cshtml , _FinancialOverview.cshtml.

//53103 [Functional] [Diversey] 3.5. CURRENT MONTH BUDGET SPEND DETAILS ON THE CHILD ACCOUNT MANAGEMENT PAGE







 expenditureInfo = CommerceFramework.Orders.GetExpenditureInfoValues(Shop.ShopAccount.ReferenceId);

Or

  expenditureInfo = ((ExtendedOrderManager)CommerceFrameworkBase.Orders).GetExpenditureInfoValues(Shop.ShopAccount.ReferenceId);

Do not call Controller directly. From the view.

Add Admin Setting , Add new Email Section to Admin


issue : https://sanacommerce.visualstudio.com/Sana%20Projects/_workitems/edit/49417/?triage=true

Ravensburger AG
Ticket 49417: 3.5. ORDER FAILURE – E-MAIL





create ExtendedStoreInfoModel model 


Add property to Web settings 


 public class ExtendedWebsiteSettings : WebsiteSettings
    {
        /// <summary>
        /// [49417] 3.5. ORDER FAILURE – E-MAIL
        /// Gets or sets the 'Orde rFailed Email Address' email address.
        /// </summary>   
        [DataMember]
        public virtual string OrderFailedEmailAddress
        {
            get { return Values.GetValue<string>(Sana.Commerce.Customization.Constants.OrderFailedEmailAddress, "scdemo@sana-commerce.com"); }
            set { Values[Sana.Commerce.Customization.Constants.OrderFailedEmailAddress] = value; }
        }
                
    }