Showing posts with label DesignPatterns. Show all posts
Showing posts with label DesignPatterns. Show all posts

Wednesday, 11 March 2020

PowerApps CRUD Operation on SharePoint List (On Premises)


Connect On Premises SharePoint with PowerApps

Time Require to read this: 5 mins


Content:
  1. PowerApps with SharePoint online and on premises
  2. Purpose of gateway and download from Microsoft site
  3. Installation and configuration of Gateway
  4. How to connect Gateway to PowerApps online
  5. Basic app development in PowerApps platform
  6. CRUD Operation on SharePoint 2016 list

1.    PowerApps with SharePoint online and on premises:

PowerApps is a platform where you can create application GUI and this application can run on top SharePoint, AX, and Power BI etc. SharePoint, AX or any supported platform will be treated as backend from where you will save or retrieve the data and show in PowerApps.
So now let’s come to our Topic:

PowerApps can be connected with Microsoft supported Platforms it can be on premises or Online. For online everything is pre-configured but challenge is to connect with on premises platforms.
For following configurations we will be using on premises SharePoint 2016

2.    Purpose of gateway and download from Microsoft site

Gateway will create a two way bridge between SharePoint and PowerApp. So this app which we are going to build in PowerApps platform will communicate with SharePoint list using this gateway.
Oh Yeah now you fasten your belt because we are going to configure gateway.
Following is the URL of Gateway setup  you need to install on SharePoint Machine
Note: Please read the perquisites require for gateway installation.

3.    Installation and configuration of Gateway

 Run the gateway exe and you will get first screen

Check the terms of Use else install button will not unable. J

Once you click install 2nd screen will be:
It will not take more time to install.

3rd screen will be:
Enter Office 365 email address in following screen.

4th Screen popup will open where you are supposed to enter password:

5th screen to select new instance or connect with already installed Gateway.


 will select Register a new gateway on this computer

6th Screen will show:
Here you need to enter any secret key and remember or save it somewhere.

Give a unique name this gateway

Hurry! Installation completed following screen will give you the status of your gateway.

4.    How to connect Gateway to PowerApps online

Following is the critical part to connect it PowerApps with this gateway.
Go to PowerApps portal using this link: https://make.powerapps.com/
Sign in with your office 365 account. You will see following screen:
Open the Data-> Connections -> New Connection

Once you click on New Connection you will get following screen:

Click on SharePoint


New Popup will open:
Select Connect using on-premises data-gateway

Stay in this popup and scroll down:

Enter your credentials you used for Gateway installation and from dropdown select your Gateway

After you click Create your Gateway connection will be added and you will get following screen:

5.    Basic app development in PowerApps platform


Click on Apps-> New app dropdown -> Canvas

Once you click it will take you to PowerApps development environment.

Select Phone Layout

Once you click Phone layout it will ask you for SharePoint 2016 on premises URL enter url and you will get your all lists available in SharePoint

Select the list and click Connect

On Successful connection you can see Expenses list data on following screen.

6.    CRUD Operation on SharePoint 2016 list


Basic Structure will be automatically created connected with this list


SharePoint list data as showing in power app

Thanks for your time and reading this.
If you stuck somewhere or need any consultancy regarding Power Automate, SharePoint and Office feel free to comment, your one question can save others time.
#SharingIsCaring

Sunday, 11 November 2018

Step by Step implementation pf Repository Pattern using C# for Beginners

Design Pattern:
         Create a pattern for your code so it can be reusable and with well maintained code. So easy to add new modules without writing too much code.

Repository Pattern:
Basic Purpose of design pattern is to have separation between Business Logic and DB calls.
Advantages:
1: Easily testable business Logic
2: Application works on API calls
3: All modules have API so it can easily integrate able with any other platforms.
4: Maximum implementation OOP concepts like Templates, Interfaces and Inheritance.

Implementation of Repository Patterns step by step:


2 step:
3rd step:
4th step:
5th step:
6th step:
7th step:
8th step:
9th step:
10th step:
11 step:
12th step:
13th step:
14th step:
15th step:
16th step:
17th step:
18th step:
19th step:


Further Implementation projects:
Common Project

1: Create folder APIResponse
2: Add 3 classes as per the image
3: Install Nuget package of Json.net in common project

4: Add AppConstant class as per the image

5: Add HttpHelper class and add below functions one function to get data and second for post

   public static List<T> DownloadSerializedJsonViaGET<T>(string url) where T : new()
        {
            using (var client = new WebClient())
            {
                try
                {
                    client.Encoding = Encoding.UTF8;
                    client.Headers[HttpRequestHeader.ContentType] = AppConstant.ContentType;
                    client.Headers[HttpRequestHeader.Accept] = AppConstant.ContentType;

                    string jsonData = client.DownloadString(url);
                    var response = JsonConvert.DeserializeObject<List<T>>(jsonData);
                    ResponseList<T> responseForCurrentObject = new ResponseList<T>();
                    responseForCurrentObject.data = response;
                    responseForCurrentObject.Message = "Successful Transaction";
                    return responseForCurrentObject.data;
                }
                catch (WebException exception)
                {
                    #region EXCEPTION HANDLING
                    var errorResponseText = "";
                    if (exception.Response != null)
                    {
                        var responseStream = exception.Response.GetResponseStream(); // Get API error and show as message
                        if (responseStream != null)
                        {
                            using (var reader = new StreamReader(responseStream))
                            {
                                errorResponseText = reader.ReadToEnd();
                            }
                        }
                    }
                    return JsonConvert.DeserializeObject<List<T>>(errorResponseText);
                    #endregion
                }

            }
        }

        public static Response<T> DownloadSerializedJsonViaPOST<T>(string url, object data, string method = "POST") where T : new()
        {
            using (var client = new WebClient())
            {
                try
                {
                    client.Encoding = Encoding.UTF8;
                    client.Headers[HttpRequestHeader.ContentType] = AppConstant.ContentType;
                    client.Headers[HttpRequestHeader.Accept] = AppConstant.ContentType;

                    var obj = JsonConvert.SerializeObject(data);

                    string jsonData = client.UploadString(url, method, obj);
                    var response = JsonConvert.DeserializeObject<T>(jsonData);
                    Response<T> responseForCurrentObject = new Response<T>();
                    responseForCurrentObject.data = response;
                    return responseForCurrentObject;
                }
                catch (WebException exception)
                {
                    #region EXCEPTION HANDLING
                    var errorResponseText = "";
                    if (exception.Response != null)
                    {
                        var responseStream = exception.Response.GetResponseStream(); // Get API error and show as message
                        if (responseStream != null)
                        {
                            using (var reader = new StreamReader(responseStream))
                            {
                                errorResponseText = reader.ReadToEnd();
                            }
                        }
                    }
                    return JsonConvert.DeserializeObject<Response<T>>(errorResponseText);
                    #endregion
                }

            }
        }



Service Project

1: Add two folder one for interface and second for implementation
 2: Implementation of interfaces



Web Project 
1: Call service function in your web project


API Project
1: Install nuget package AutoMapper in your api project
2: Do basic configuration for Mapper. (Auto Mapper is for to map input entities with db context entities)
3: Create Folder DTO in Common project 
4: Copy entities from Model and paste in UserDTO class

5: Use auto mapper as per the below image in your API project controller:




In case of any query feel free to reach me. Thanks for reading the blog.