Sunday, January 8, 2023

Authentication and Authorization using Azure Active Directory - Part 1

  •  Authentication and Authorization using Azure Active Directory - Part 1

This explains all about setting up azure ad to Authenticate web/web api

Steps.


  • 1.       Create tenant or choose default tenant
  • 2.       Register an app
  • 3.       Add secret
  • 4.       Add permissions -- Permission needed User.ReadWrite.All AppRoleAssignment.ReadWrite.All
  • 5.       Grant admin permission to these newly added permission
  • 6.       Add roles “say - admin,guest”


and all set.. follow below screenshots


          1.




























Friday, May 7, 2021

Get email once have vaccine slots in center of your choice of your area

  Get email once have vaccine slots in center of your choice of your area

link to download console app. for same as below

https://github.com/sunitkanyan/CowinAvailalitySlotEmailCSharp


CowinAvailalitySlotEmailCSharp

can enhance it as per your requirement -

this code can run as scheduled job and can suite you email on availablity of slot as per hospital name nearby you just need to set pincode.

Provide list of center with slots

you can set it as scheduled job

set hit every 5 mins and it will sent you email once slots in your pin .


Change pin in line 

var client = new RestClient(string.Format("https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByPin?pincode=122001&date={0}-{1}-2021",day, month));





Change email setting email address and pwd .. and enable less secure app setting for this google account


smtp.Credentials = new NetworkCredential("testemail@gmail.com", "ac12345677");


To email address  mail.To.Add("testemail123@gmail.com");

Drop email to use as





Sunday, October 16, 2016

Physical Location of Records in SQL Server


The unit of data storage in SQL Server is the page.The disk space allocated to  mdf file in a database is logically divided into pages numbered contiguously from 0 to n and all disk I/O operations are performed at the page level.

The page size is 8 KB (8192 bytes). So SQL Server databases have 128 pages/MB.

Each page begins with a 96-byte header that is used to store system information about the page. This information includes the page number, page type, the amount of free space on the page, and the allocation unit ID of the object that owns the page.

Say one of the pages in your table is corrupt and while repairing the corrupt pages, you may eventually end up loosing some data. You may want to find out which records are on the page.


To do so, use the following undocumented T-SQL %%physloc%% virtual column:



Query:

SELECT *, %%physloc%% AS physloc
FROM Person.Address
ORDER BY physloc


As you can see, the last column represents the record location. However the hexadecimal value is not in a human readable format. To read the physical record of each row in a human readable format, use the following query:


SELECT * 
FROM Person.AddressType 
CROSS APPLY sys.fn_PhysLocCracker(%%physloc%%)

this query will provide the hexadecimal address in form of page_id,slot_id

However this system tabular function fn_PhysLocCracker is available only in 2008 and above.


Original Article: https://blogs.msdn.microsoft.com/sql_pfe_blog/2016/09/15/where-is-a-record-really-located/


Sunday, July 3, 2016

Creating custom object and consuming in webapi - Sales force

Creating custom object and consuming in webapi 

There are numbers of standard objects in Sales force. Depending on the requirement, sometime we might require to create some custom objects in sales force.

This article is all about "how we can create the custom objects in sales force and how we can consume them in asp.net webapi"

Custom Object: -

Custom objects are database tables that allow you to store data specific to your organisation in Salesforce. You can use custom objects to extend Salesforce functionality or to build new application functionality. 
Once you have created a custom object, you can create a custom tab, custom related lists, reports, and dashboards for users to interact with the custom object data. You can also access custom object data through the Force.com API.

Creating Custom Object:-

Sign-in in force.com
Move to [SetUp] >> Build >> Create >> Objects and click on "New Custom Object"

provide required details and choose from optional permission handing (i.e. enable note on record etc..) and click same



Custom objects named "MyCustomObject" is ready. You can note down the API Name for cutom objects as it will be required while querying on this objects from api.

Only following standard fields created when custom object get created 

  • CreatedBy
  • LastModifyBy
  • Name
  • Owner




Creating Custom fields:-

We had added new custom objects but that does have only standard fields yet but we require fields to store data. The user defined fields on a custom objected termed as custom fields in sales force. It is very easy to create simple field or look up field.

[Custom Fields & Relationship] >> [New]

Same we create a field/column in db, we have information 
  • what type of column it would be
  • what type on constraint can be applied on it
  • what will be length of column
  • it is be a look up column
very similar way sales force is asking detail while creating custom fields.because at the end it will be column in sales force db somewhere.



Choose data type and click next.
Set field level security in step 3 and last step show  basis detail of field , can set page layout.

View all Custom Objects:-

[SetUp] >> Build >> Create >> Objects


Performing read on custom object from web api:-


Code to access:-


namespace MyFirstSalesForceAPI.Controllers
{
    public class CustomSalesForceObjController : ApiController
    {
        private static string _consumerKey = "3MVG9ZL0ppGP5UrB3oyPJP28HLRAP8yV0mp4qqcVRgbZ7EdGT96I0t6AHO22xth8C_R8tkPI0qo270C5eH9R7";//your consumer key
        private static string _consumerSecret = "2970133464515046181";//your key secret
        private static string _userName = "sunitkanyan@sunitkanyan.in";

        private static string _securityToken = "N2fwK2ZEZBwH0blYMm4zYQptP";//your securitytoken
        private static string _password = "YourPassword" + _securityToken;



        // GET api/CustomObject/objectName
        [HttpGet]
        public IEnumerable<dynamic> Get()
        {
            var auth = new Salesforce.Common.AuthenticationClient();
            auth.UsernamePasswordAsync(_consumerKey, _consumerSecret, _userName, _password).Wait();

            var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);
            Task<QueryResult<dynamic>> res = client.QueryAsync<dynamic>("Select Id,Name,MyFSFApp__Email__c, MyFSFApp__Mobile__c from  MyFSFApp__Student__c");
            res.Wait();

            return res.Result.Records.AsQueryable();
        }
    }
}

Result



View in sales force


~
Technocrats