Archive for May, 2017

How to read config settings in Asp.Net Core

Introduction

In this article I will explain the details of how to read config settings in Asp.Net Core.

Description

In Asp.Net webforms we used web.config file to store the config values like a connection string, appsettings etc.However, in Asp.Net core, the config file doesn’t exist anymore.  Instead, we have a slightly different approach where the configuration API provides a way of configuring an app based on a list of name-value pairs that can be read at runtime from multiple sources. You can read the config values from multiple sources like JSON, XML etc.

In this article we will examine how to implement config files based on JSON formats in Asp.Net Core application.

Add the Required references

To read the values from appsettings.json, we need to add the below references to project

Add appsettings.json file to store config values

We will store the config items as Name:Value pair in this json file.  You can also add hierarchical list in json file where each items will be separated by comma.

Sample value

Create ConfigurationBuilder in Startup.cs class

We use AddJsonFile” method in JsonConfigurationExtensions class to provide the Json File path. To reload the configuration file if the file changes we can set the reloadOnChange property.  You can find details of AddJsonFile method here.

Read the value from appsetttings.json file

Using the GetSection method we can access the values from appsettings.json file

Complete Code

You can find the complete source code for this article here

, , ,

Leave a comment

Implementing delete functionality in UIGrid

Introduction

This is continuation to my previous two articles in which I demonstrated the steps to

In this article I am going to demonstrate how to implement row delete functionality in UIGrid.  The series will contain continuation articles to cover the topic in detail.

Prerequisites:

I have used icons from FontAwesome Library, which is a great source for  icons. You can download Fontawesome icons from here.

Also to display message after every operation we used UIBootstrap

Implementation:

You would already have the Model configured by following my previous article on loading UIGrid with data. We will directly look into the details of deleting records in UIGrid.

Sample Demo of Delete functionality is given below

Demo

UIGrid Updates:

We will update cellTemplate in “Actions” column to add Delete button. We will reuse the editRow flag to hide and display delete buttons.  To delete the record,, we call deleteRow function from Delete button

Delete function:

Delete function will take the selected row object as input parameter; we will find the rowindex using input parameter. Using row index we will find CustomerID of selected row and delete the record. Additionally before deleting the record we will ask for user confirmation. Finally we will call the DeleteCustomer method in Factory service to delete the record in database.

Updated Angular code with Delete functionality

HTML

Delete Customer Method(WEBAPI)

 

, , , ,

Leave a comment