Pages

Wednesday, November 23, 2022

Delete a language and its content from Optimizely CMS from the backend

You can download the database of the specific environment from the PAAS portal and install it locally 

To find the language id in your database run the SQL:

 
SELECT TOP 1000 [pkID]
     ,[LanguageID]
     ,[Name]
     ,[SortIndex]
     ,[SystemIconPath]
     ,[URLSegment]
     ,[ACL]
     ,[Enabled]
 FROM [YOUR_DB].[dbo].[tblLanguageBranch]
 
Example of deleting language - 7 is Spanish in my database

DELETE FROM [YOUR_DB].[dbo].[tblContentLanguage]
  WHERE fkLanguageBranchID = 7

   DELETE FROM [ YOUR_DB].[dbo].[tblContentLanguageSetting]
WHERE fkLanguageBranchID = 7

DELETE FROM [YOUR_DB].[dbo].[tblContentProperty]
  WHERE [fkContentID] IN (SELECT [pkID] FROM [YOUR_DB].[dbo].[tblContent] WHERE [fkMasterLanguageBranchID] = 7)

DELETE FROM [YOUR_DB].[dbo].[tblContentSoftlink]
  WHERE [fkOwnerContentID] IN (SELECT [pkID] FROM [YOUR_DB].[dbo].[tblContent] WHERE [fkMasterLanguageBranchID] = 7)

 DELETE FROM [YOUR_DB].[dbo].[tblContent]
  WHERE [fkMasterLanguageBranchID] = 7
 
 DELETE FROM [ YOUR_DB].[dbo].[tblLanguageBranch]
WHERE pkID = 7

After you confirm that it works locally, create a ticket with the customer support and then have them run these sql queries

Thursday, November 3, 2022

Left join using LINQ to SQL

 public IActionResult GetDealerByReference(string countryCode, string dealerId)

{

    if (string.IsNullOrEmpty(countryCode))

    return BadRequest("country code cannot be empty");

    if (string.IsNullOrEmpty(dealerId))

        return BadRequest("dealerId cannot be empty");

    string toBeReplaced = "'INSPIRA', 'OTHER', ";

    // this is of type System.Linq.IQueryable 

    var webDealerItemRestrictions = _repository.CacheJdeDealerItemRestriction.FindAll();

    // this is of type System.Linq.IQueryable 

    var webDealerAddresses = _repository.CacheJdeDealerAddress.FindAll();

    //left join webDealerAddresses with webDealerItemRestrictions

    var result = (from addresses in webDealerAddresses.Where(x => x.DealerID == dealerId &&                         x.CountryCode == countryCode)

            from restrictions in webDealerItemRestrictions

            .Where(x => addresses.DealerID == x.DealerID)

            .DefaultIfEmpty()

             select new { addresses, restrictions }).FirstOrDefault();

   if (result == null) return NotFound("Not Found");

   var webDealer = new WebDealers()

   {

    Code = result.restrictions.Code,

    Address1 = result.addresses.Address1,

    Address2 = result.addresses.Address2,

   AreaCode = result.addresses.AreaCode,

   Brands = result.addresses.BrandListing.Replace(toBeReplaced, ""),

   CountryCode = result.addresses.CountryCode,

   DealerName = result.addresses.DealerName,

   EmailAddress = result.addresses.EMailaddress,

   PhoneNumber = result.addresses.PhoneNumber

  };

  return Ok(JsonConvert.SerializeObject(new List<WebDealers>() { webDealer }));

}