Breaking

Friday, July 31, 2020

7:37 AM

Data Annotation and their types in MVC ?

mvc
Data Annotations are nothing but certain validations that we put in our models to validate the input from the user. ASP.NET MVC provides a unique feature in which we can validate the models using the Data Annotation attribute. Import the following namespace to use data annotations in the application.
System.ComponentModel.DataAnnotations
It is very easy to use and the code becomes much cleaner as compared to normal ASP.NET validators.
Let us understand some of the validator attributes that we can use in MVC.
Types of Data Annotations in ASP.NET MVC
Required
This attribute specifies that the value is mandatory and cannot be skipped.
Syntax
[Required(ErrorMessage="Please enter name"),MaxLength(30)]
DataType
This attribute is used to specify the datatype of the model.
Syntax
[DataType(DataType.Text)]
Range
Using this attribute we can set a range between two numbers.
Syntax
[Range(100,500,ErrorMessage="Please enter correct value")]
StringLength
Using this attribute we can specify maximum and minimum length of the property.
Syntax
[StringLength(30,ErrorMessage="Do not enter more than 30 characters")]
DisplayName
Using this attribute we can specify property name to be displayed on view.
Syntax
[Display(Name="Student Name")]
MaxLength
Using this attribute we can specify maximum length of property.
Syntax
[MaxLength(3)]
Bind
This attribute specify fields to include or exclude for model binding.
Syntax
[Bind(Exclude = "StudentID")]
DisplayFormat
This attribute allows us to set date in the format specified as per the attribute.
Syntax
[DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}")]
RegularExpression
We can set a regex pattern for the property. For ex: Email ID.
Syntax
[RegularExpression(@"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$", ErrorMessage = "Email is not valid.")]

Wednesday, July 29, 2020

1:46 AM

Difference between ApiController and Controller in ASP.NET MVC ?

 
Note
If you have worked with ASP.NET MVC, then you are already familiar with controllers. They work similarly in Web API, but controllers in Web API derive from the ApiController class instead of Controller class. The first major difference you will notice is that actions on Web API controllers do not return views, they return data.
ApiControllers are specialized in returning data. For example, they take care of transparently serializing the data into the format requested by the client. Also, they follow a different routing scheme by default (as in: mapping URLs to actions), providing a REST-ful API by convention.

You could probably do anything using a Controller instead of an ApiController with the some(?) manual coding. In the end, both controllers build upon the ASP.NET foundation. But having a REST-ful API is such a common requirement today that WebAPI was created to simplify the implementation of a such an API.

It's fairly simple to decide between the two: if you're writing an HTML based web/internet/intranet application - maybe with the occasional AJAX call returning json here and there - stick with MVC/Controller. If you want to provide a data driven/REST-ful interface to a system, go with WebAPI. You can combine both, of course, having an ApiController cater AJAX calls from an MVC page.

To give a real world example: I'm currently working with an ERP system that provides a REST-ful API to its entities. For this API, WebAPI would be a good candidate. At the same time, the ERP system provides a highly AJAX-ified web application that you can use to create queries for the REST-ful API. The web application itself could be implemented as an MVC application, making use of the WebAPI to fetch meta-data etc.

Monday, July 27, 2020

10:43 PM

What is Slack and How Can we Use It ?


You’ve probably heard a lot about Slack - the messaging app that almost every workplace seems to be using.
Let’s take a look inside.
What is Slack?
Slack is essentially a chat room for your whole company, designed to replace email as your primary method of communication and sharing.
Its workspaces allow you to organize communications by channels for group discussions and allows for private messages to share information, files, and more all in one place.
Plus, Slack integrates with a host of other apps so you can manage your entire workflow through one platform.
Teams & Workspaces
Slack allows businesses, communities, and other organizations to create a private, dedicated workspace complete with a custom URL.
After a simple signup process, you’ll be able to invite your team to join and start getting work done.

Friday, July 24, 2020

9:27 PM

Read a csv file in C#

CSV is a file that contains data seperated by commas. In this tutorial, i will show you how to read a CSV file in C#.

Read CSV

For the purpose of this tutorial, we will use the below csv sample data.
The file contains 16 records and each record contains 3 columns (Last name, First name and SSN) seperated by commas.
The following code illustrates how to read the above csv file.

// path to the csv file
string path = "C:/Users/overl/Desktop/people.csv";
string[] lines = System.IO.File.ReadAllLines(path);
foreach(string line in lines)
{
string[] columns = line.Split(',');
foreach (string column in columns) {
// Do something
}
}

In preceding code, we use the ReadAllLines method of the File object to read all content of our csv file. ( the path of the csv file is passed as a parameter of the method). The ReadAllLines method returns a string array containing all lines of the file. Since the information contained in each line is seperated by a comma, we use the Split method in order to get that information.

Namespace
To use the File object and its methods, you have to include the following namespace :

using System.IO;
8:43 PM

Top 22 LINQ Interview Questions & Answers

1) Explain what is LINQ? Why is it required?
Language Integrated Query or LINQ is the collection of standard query operators which provides query facilities into.NET framework language like C#, VB.NET.
LINQ is required as it bridges the gap between the world of data and world of objects.
2) What are the types of LINQ?
  • LINQ to Objects
  • LINQ to XML
  • LINQ to Dataset
  • LINQ to SQL
  • LINQ to Entities
3) Explain how LINQ is useful than Stored Procedures?
  • Debugging: It is difficult to debug a stored procedure but as LINQ is part of.NET, visual studios debugger can be used to debug the queries
  • Deployment: For stored procedure, additional script should be provided but with LINQ everything gets compiled into single DLL hence deployment becomes easy
  • Type Safety: LINQ is type safe, so queries errors are type checked at compile time
4) List out the three main components of LINQ? Explain what is the extension of the file, when LINQ to SQL is used?
Three main components of LINQ are
  • Standard Query Operators
  • Language Extensions
  • LINQ Providers
The extension of the file used is .dbml
5) Define what is Where clause and Let clause?
  • Where clause: It allows adding some conditional filters to the query.
  • Let clause: It allows defining a variable and assigning it a value calculated from the data values.
6) Explain why SELECT clause comes after FROM clause in LINQ?
With other programming language and C#, LINQ is used, it requires all the variables to be declared first. “FROM” clause of LINQ query defines the range or conditions to select records. So, FROM clause must appear before SELECT in LINQ.
7) Explain what is the use of System.XML.Xlinq.dll?
System.Data.Dlinq.dll provides the functionality to work with LINQ to SQL
8) Explain what is lambda expressions in LINQ?
Lambda expression is referred as a unique function use to form delegates or expression tree types, where right side is the output and left side is the input to the method. For writing LINQ queries particularly, Lambda expression is used.
9) Explain how LINQ with databases can be used?
LINQ supports XML, SQL, Dataset and Objects. Through LINQ to objects or LINQ to Datasets one can use LINQ with other databases. The objects and datasets take care of database particular operations, and LINQ only needs to deal with those objects and not the database operations directly.
10) Explain what is the difference between Skip() and SkipWhile() extension method?
  • Skip() : It will take an integer argument and from the given IEnumerable it skips the top n numbers
  • SkipWhile (): It will continue to skip the elements as far as the input condition is true. It will return all remaining elements if the condition is false
11) In LINQ how will you find the index of the element using where () with Lambda Expressions?
In order to find the index of the element using where () with the lambda expression
Where ( ( i, ix ) => i == ix);
12) Explain how you can assign a lambda expression to a delegate?
To assign a lambda expression to a delegate
Delegate int del (int i);
Del myDelegate=x=>x*x;
Intj = myDelegate (4); //j=16
13) Explain what is the difference between Statement Lambda and Expression Lambda?
  • Expression Lambdas are extensively used in the construction of Expression Trees
  • To create expression trees statement lambdas cannot be used
14) Mention what is the role of DataContext classes in LINQ?
DataContext class acts as a bridge between SQL Server database and the LINQ to SQL. For accessing the database and also for changing the data in the database, it contains connections string and the functions.
15) Explain what are LINQ query expressions?
Query expression is nothing but an LINQ query. It is a combination of query clauses that identifies the data sources for a query. It contains information for sorting, filtering, grouping or joining to apply to the source data. It determines what information should be retrieved from the data source.CV.
16) Explain what are compiled queries?
In compiled LINQ queries, the plan is cached in a static class and static class is a global cache. Rather than preparing the query plan from scratch, LINQ prepares plan using stating class object.
17) Explain how standard query operators useful in LINQ?
Standard Query Operators useful in LINQ are
  • Get a total count of elements in the collection
  • Order the results of a collection
  • Grouping
  • Computing average
  • Joining two collections based on matching keys
  • Filter the results
18) Explain what is the purpose of LINQ providers in LINQ?
LINQ providers are set of classes that take an LINQ query which generates method that executes an equivalent query against a particular data source.
19) Explain how you can retrieve a single row with LINQ?
To retrieve a single row with LINQ we need
Public User GetUser (string userName)
{
DBNameDataContext myDB = new DBNameDataContext ( ) ;
User user = myDB. Users. Single ( u, u.UserName => userName );
Return user;
}
20) LINQ query is executed in which statement?
In VB, an LINQ query is executed in the For Each Statement, and in the foreach statement for C#.
21) Explain what is “LINQ to Objects”?
When LINQ queries any IEnumerable(Of T) collection or IEnumerable directly without the use of an intermediate LINQ provider or API such as LINQ to SQL or LINQ to XML is referred as “LINQ to Objects.”
22) Explain how you can differentiate between Conversion Operator “ToDictionary” and “IEnumerable” of LINQ?
To solve the conversion type problems “IEnumerable” and “ToDictionary” conversion operator are used.
“ToDictionary” conversion operator is the instance of Dictionary (k, T). The “keySelector” predicate recognizes the key of each item, while “elementSelector”, is used to extract each single item, if it is given.
Extension method on “IEnumerable” is.AsEnumerable. AsEnumerable simply returns the source sequence as an object of type IEnumerable <T>.

Thursday, July 23, 2020

6:35 PM

Advantages & Disadvantages of SSRS

Advantages of using SSRS

  • It is faster and cheaper.
  • Efficient reporting access to information that is residing in both MS SQL Server database or Oracle
  • No need for expensive specialist skills
  • In SSRS the default report designer is integrated with Visual Studio .NET. This allows us to create an application and reports in the same environment.
  • The security is managed in a role-based method which can be applied to folders and reports.
  • Subscription-based reports are automatically sent to the users.
  • Faster production of reports on both relational and cube data
  • Real time information to the business, providing better decision support

Disadvantages of using SSRS

Some limitations of SSRS are given below:
  • There is no print button. So if you want to print something you need to export PDF, excel, word or other formats.
  • All reports need parameters to be accepted by users.
  • It is difficult to make changes in the custom code and debug expressions.
  • Does not allow you to add page number or total pages in the report body
  • Does not offer any method to pass values form sub-reports to the main report
  • Page header always creates extra spaces on every new page.
6:32 PM

Type of SSRS reports


Here, are types of reports which you can develop using SSRS tool.
Report Type NameDetail
Parameterized reportsThis type of report uses input values to complete report or data processing.
Linked ReportsA linked report offers a point to an existing report. This type of report is derived from an existing report and retains the original's report definition.
Snapshot reportsA snapshot report contains layout information and query results which can be retrieved at a specific point in time.
Cached ReportsThe cashed report allows you to create a copy of the processed reports. They are used to enhance the performance by reducing the number of processing requests and time to retrieve large reports.
Drill down ReportsDrill down reports helps you to hide complexity. It allows users toggle between hidden reports items to control how much detail data you want to see. It must retrieve all possible information that can be shown in the report.
Drillthrough ReportsDrillthrough reports are standard reports which can be accessed through a hyperlink on a text box in the original report. It works with the main report and is the target of a drill through an action for a report item like a placeholder text or a chart.
SubreportsAs the name suggests, sub-reports is a report which displays another report inside the body of the main report.
6:29 PM

What is RDL ?

Report Definition Language is shortly known as RDL. It describes all possible elements of a report using an XML grammar which is validated by an XML schema.
The report definition of an individual report is based on RDL. It contains instructions for rendering the design of the report at the run time.
6:28 PM

Reporting Life Cycle

Every organization follows a standard reporting lifecycle which can be classified as follows:
Authoring: In this phase, the report author defines the layout and syntax of the data. The tools used in this process are the SQL Server Development Studio and SSRS tool.
Management: This phase involves managing a published report which is mostly part of the websites. In this stage, you need to consider access control over report execution.
Delivery: In this phase, you need to understand when the reports need to be delivered to the customer base. Delivery can be on-demand or pre-defined schedule. You can also add an automation feature of subscription which creates reports and sends to the customer automatically.
6:26 PM

SSRS Architecture

SSRS Architecture
SSRS has quite a complex architecture. The report services architecture includes development tools, administration tools, and report viewers.
Here, are important components of SSRS

Report Builder

It is an ad-hoc report publishing tool that is executed on a client's computer. It has a drag and drop interface that is easy to use.

Report Designer

The Report designer tool helps to develop all types of reports. It is a publishing tool, that is hosted in Visual Studio or Business Intelligence Development Studio (BIDS).

Report Manager

The report managers check the report, matching it with the given requirements. They make decisions based on those reports.

Report Server

It is a server which uses the SQL Server database engine to store metadata information

Report server database

It stores metadata, report definitions, resources, security settings, delivery data, etc.

Data sources

Reporting services retrieve data from data sources like relational and multidimensional data sources.
6:23 PM

How SSRS Works ?

  1. The report users are the peoples who work with the data as well as want some insights from data. They send a request to the SSRS server
  2. SSRS server finds the metadata of the report and sends a request for data to the data sources.
  3. Data returned by the data source is merged with the report definition into a report.
  4. When the report is generated, it is returned to the client.
6:18 PM

Features of SSRS

  • Offers a Simple Object Access Protocol (SOAP) application and pluggable architecture
  • Retrieve data from managed, OLE ODBC, and DB connections
  • Allows you to create adhoc reports and save them to the server
  • Display data in a variety of formats which includes tabular, free-form, and charts
  • Create custom controls by using report-processing extension
  • Embed graphics, images to the reports. You can also integrate with external content using SharePoint
  • You can store and manage custom reports
  • Chart and Gauge control feature allows you to display KPI data
6:10 PM

Why SSRS ?

Here, are prime reasons for using SSRS tool:
  • SSRS is an enhanced tool compared to Crystal Reports
  • Faster processing of reports on both relational and multidimensional data
  • Allows better and more accurate Decision-making mechanism for the users
  • Allows users to interact with information without involving IT professionals
  • It provides a World Wide Web-based connection for deploying reports. Hence, reports can be accessed over the internet
  • SSRS allows reports to be exported in different formats. You can deliver SSRS reports using emails
  • SSRS provides a host of security features, which helps you to control, who can access which report.

Example of SSRS reporting

Consider an example of a medical research institute where patients are recruited for various clinical trials.
The staff in the institute creates a database record for each patient.
Once they agree to be part of the trial, and the hospital gets the payment form the drug company based on the price at which it is ready to participate.
Without SSRS, the medical institute would need to manually email a report to the pharma company with the total number of weekly participants. The institute must also add details of every patient included in the trial, the number of drugs used, and all the unwanted situations. As a result, the time taken to collect and send this data in the correct format may consume loads of valuable time in the clinic.
If the institute were recording data, with the help of SSRS tool, they would be able to produce on-demand reports in a pre-defined format.
With SSRS, the drug company can access the report on the cloud, run the report at any time to get the latest data from the clinic.
6:07 PM

What is SSRS ?


SQL Server Reporting Services (SSRS) is a reporting software that allows you to produce formatted reports with tables in the form of data, graph, images, and charts. These reports are hosted on a server that can be executed any time using parameters defined by the users. It is part of Microsoft SQL Server Services suite.

Types of reporting services

Microsoft SQL Server Integration services which integrate data from different sources.
Microsoft SQL Server Analytical service which helps for the analysis of the data
Microsoft SQL Server Reporting service allows for generating a visual report of the data.

Sunday, July 12, 2020

Saturday, July 11, 2020

6:35 AM

What is Onion Architecture ?

As we said in the introduction, the concept of Onion Architecture is closely connected to two other architectural styles – Layered and Hexagonal. Similarly to the Layered approach, Onion Architecture uses the concept of layers, but they are a little different:
  • Domain Model layer, where our entities and classes closely related to them e.g. value objects reside
  • Domain Services layer, where domain-defined processes reside
  • Application Services layer, where application-specific logic i.e. our use cases reside
  • Outer layer, which keeps peripheral concerns like UI, databases or tests
Those layers when presented as circles, each wrapping around the previous one, form the famous “onion”:

Benefits of an Onion Architecture

  • Plays well with DDD – that should not be a surprise for an architecture that builds everything on top of a domain model
  • Directed coupling – the most important code in our application depends on nothing, everything depends on it
  • Flexibility – from an inner-layer perspective, you can swap out anything in any of the outer layers and things should work just fine
  • Testability – since your application core does not depend on anything else, it can be easily and quickly tested in isolation

Drawbacks of an Onion Architecture

  • Learning curve – I don’t know why, but people tend to mess up splitting responsibilities between layers, especially harming the domain model
  • Indirection – interfaces everywhere!
  • Potentially heavy – if you look at Palermo’s project, the application core has no dependencies towards frameworks, even NHibernate, a cousin of Java’s Hibernate. Implementing things this way in Java would not be so easy unless you want to jump into XML files (yay!)