Tuesday, December 20, 2016

Techinical URL's


AngularJS:

https://www.youtube.com/watch?v=YUXirJ5-Uug&index=12&list=PLYxzS__5yYQmX2bItSRCqwiQZn5dIL1gt

https://www.youtube.com/watch?v=436sRs9ebMM //AJS & MVC

https://www.youtube.com/watch?v=RYJ32yq_Ekg // AJS & MVC Complete LifeCycle Video

https://www.youtube.com/watch?v=7XHbybYR3jc //AJS & MVC Routing

https://www.youtube.com/watch?v=7TzaJ7Q_vbE //NodeJS Good Video

https://www.youtube.com/watch?v=U8XF6AFGqlc //NodeJS Absolute Beginner

https://www.youtube.com/watch?v=oMgvi-AV-eY  //asp.net mvc5 angularjs 2

AutoMapper:-

https://www.youtube.com/watch?v=-5sZ7hq3J10&list=PLKMjnVoE2q95MalgqjlzRK-ZefZ50bd6A&index=2

 ----------------- Async and Await  URLS ------------------------------------
https://msdn.microsoft.com/en-us/magazine/dn802603.aspx
https://www.emailarchitect.net/easendmail/kb/csharp.aspx?cat=12
http://stackoverflow.com/questions/8747483/proper-way-to-asynchronously-send-an-email-in-asp-net-am-i-doing-it-right
https://stephenhaunts.com/2014/10/10/simple-async-await-example-for-asynchronous-programming/
https://dotnetcodr.com/emailing/

http://kevin-junghans.blogspot.in/2013/10/adding-email-confirmation-to-aspnet.html //Good Example Code
https://code.msdn.microsoft.com/ASPNET-MVC5-SendEmail-and-09e6cf76 //Good Example Code
http://www.mikesdotnetting.com/article/268/how-to-send-email-in-asp-net-mvc //Good Example Code

https://www.asp.net/web-forms/overview/performance-and-caching/using-asynchronous-methods-in-aspnet-45

http://www.mikesdotnetting.com/article/268/how-to-send-email-in-asp-net-mvc //Upload File using Async


------WebAPI-----------------
https://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-and-action-selection //Main
https://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api
https://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
https://weblog.west-wind.com/posts/2012/may/08/passing-multiple-post-parameters-to-web-api-controller-methods
http://stackoverflow.com/questions/14407458/webapi-multiple-put-post-parameters
http://stackoverflow.com/questions/25161665/multiple-parameters-in-a-web-api-2-get
http://stackoverflow.com/questions/10937524/how-should-i-pass-multiple-parameters-to-an-asp-net-web-api-get
http://www.dotnetcurry.com/aspnet/1278/aspnet-webapi-pass-multiple-parameters-action-method
http://www.infoworld.com/article/3136743/application-development/how-to-pass-multiple-parameters-to-web-api-controller-methods.html

------------------------------------------------------------

Merge Files and adding BookMarks


http://stackoverflow.com/questions/20636690/merge-a-list-of-pdfs-and-create-new-bookmarks-c

http://www.codeproject.com/Articles/28283/Simple-NET-PDF-Merger


-----------------------------------------------------------

https://chocolatey.org/

Chocolatey Demonstration:

 https://www.youtube.com/watch?v=HlnTZF3H1Ac 



Monday, October 17, 2016

Scan for Virus while uploading document in asp.net.using ClamAV(OpenSource) software


Download latest ClamAV from "https://www.clamav.net/downloads"

Download .zip folder(clamav-0.99.2.tar.gz this is latest while at time of writing this blog) unzip .tar file you will get "ClamAV-x64" folder.

Using command prompt navigate to "ClamAV-x64" folder and execute below commands.

freshclam.exe  software will update, if you get

"ERROR: Can't open/parse the config file D:\ClamAVx64\freshclam.conf"

this means config files does not exist, COPY clamd.conf.sample and freshclam.conf.sample  files from "conf_examples" folder, and rename them to clamd.conf and freshclam.conf respectively.

Now run command "freshclam.conf" you will get below error:-

ERROR: Please edit the example config file D:\ClamAVx64\freshclam.conf
ERROR: Can't open/parse the config file D:\ClamAVx64\freshclam.conf

then open "freshclam.conf" and COMMENT OR REMOVE "Example" line in config file

Now run command "freshclam.conf" you will get below error:-

 ERROR: Can't change dir to D:\ClamAVx64\database

The above error means database folder does not exit create folder with name database (we can change folder name in config file)

 Now run command "freshclam.conf", this time it should run successfully with below message

ClamAV update process started at Mon Oct 17 16:35:14 2016
main.cvd is up to date (version: 57, sigs: 4218790, f-level: 60, builder: amishh
ammer)..................

once update process is complete run "clamd.exe" you will get below error:-

ERROR: Please edit the example config file D:\ClamAVx64\clamd.conf
ERROR: Can't open/parse the config file D:\ClamAVx64\clamd.conf

open "freshclam.conf" and COMMENT OR REMOVE "Example" line in config file,

UnComment "TCPSocket("3310 by default) and "TCPAddr"(127.0.0.1) and


MaxEmbeddedPE
MaxHTMLNormalize
MaxHTMLNoTags
MaxScriptNormalize
MaxZipTypeRcg
 
now run  "clamd.exe" it will start, keep to command prompt and test you application..

Now clamd server is running on localhost on 3310 port. 
 
 
Reference Link:-
https://www.clamav.net/downloads
http://architectryan.com/2011/05/19/nclam-a-dotnet-library-to-virus-scan/#.WASr1aJvqPt
http://askubuntu.com/questions/250290/how-do-i-scan-for-viruses-with-clamav ---Commands
 
 
Happy coding...;-)
 

Monday, October 3, 2016

Get Biggest UserName in postgres.

Get Biggest UserName in postgres:-

select max(char_length(user_name)),user_name from users group by user_name order by max(char_length(user_name)) desc;

Monday, September 12, 2016

Elmah Asp.Net

.NET Logging Tools and Libraries

What's Logging?

Before we dig into the large number of logging frameworks, let's spend a bit of time discussing the terms related to logging. Logging as a single term, means storing messages from your application somewhere. These messages are often used for debugging errors, but I've seen log data used for multiple other purposes like creating a dashboard, monitoring updates, audit trails etc. The nice thing about logging is, that you're in control if a message should go into the log or not.
As mentioned, most people use logging frameworks for logging exceptions and other messages making it possible to debug errors in production. All of the frameworks mentioned in this post support error logging, while few actually build error management features on top of the log. Error management actually helps you monitor and deal with your errors in a more intelligent way than having to look through log files. More on that subject later.

Logging Frameworks

We've compiled a list of logging frameworks for .NET. There's a great deal of options out there, but a lot of them are no longer maintained. The list provided in this section contains the popular choices.

log4net

Probably the oldest logging framework on the block, log4net have existed pretty much since .NET was introduced. log4net was originally an internal Apache log4j port developed by Neoworks Limited back in 2001. The project quickly moved to Sourceforge (the GitHub of 2001) and was released under the Apache license. Since that time, log4net has been one of the most popular choices in the .NET world for adding logging to applications.
log4net works with the concept of appenders, where log messages can be routed to different data stores. A lot of appenders have been implemented during the years, like logging to the file system, SQL Server, HTTP endpoints and even NoSQL databases. Being unstructured text messages, log4net and NoSQL don’t exactly go hand in hand.

ELMAH

Back in 2004, Atif Aziz spotted something important. Websites sometimes fails without we as web developers actually spotting the errors. That's why he decided to create ELMAH. While ELMAH can be used as a logging framework, the focus is entirely upon errors. While we still see people misusing ELMAH to log debug messages, ELMAH is after 12 years still the best choice of logging uncaught errors in your websites.

NLog

While log4net quickly became the default choice, alternatives began to show up. Probably the first real competitor to log4net's dominance were NLog. Originally developed by Jarek Kowalski and with pull requests from almost 100 people, NLog is a great alternative. While log4net pretty much stood still from 2006, NLog just kept going. While Jarek seemed to pull the plug when starting at Google, the community seemed to step up and new releases are still flowing.
Like log4net, NLog contains multiple log targets, and is able to log messages to various data stores.

Serilog

In 2013, the .NET logging framework were taken by storm once again. When everyone else were logging text messages, Micholas Blumhardt did something new: structured logging. Unlike existing logging frameworks, Serilog introduced .NET developers to structured event data rather than dumb text messages. Serilog quickly became one of the fastest moving projects in the .NET community and still is. We really recommend you to look into Serilog for logging messages from your .NET apps.

Error Management

We wanted to put some words on the terms Error Management. We often talk to people that don't realize, that there's a big difference between Error Logging and Error Management. While log4net, NLog and Serilog are great choices for logging text-based or structured log messages to a text file or a database, this is simply not enough to monitor your websites and act on errors. Having a log file is one thing. Even with cool storage choices like Seq and Elasticsearch, having a system for monitoring and handling errors is an essential part of web application development today.
A lot of choices showed up during the last few years. elmah.io, New Relic, Raygun and Stackify are all examples of popular choices for implementing error management. All run in the Cloud and provides easy integration with your .NET websites. When looking through the different solutions, some basic features work pretty much the same way, while others vary by product. Some focus on supporting a lot of different programming languages, others on integrating with logging frameworks and some on integrating with third party systems like Slack and GitHub.
At elmah.io, we are working hard to create the best error management system for .NET web applications. We support all the major logging frameworks and tools for .NET like ELMAH, log4net, NLog and Serilog. We also provide some unique features for .NET developers like Visual Studio integration and one-click installation through NuGet. We definitely want you to try out elmah.io for your error management needs in .NET.

http://blog.elmah.io/dot-net-logging-tools-and-libraries/

http://ebanshi.cc/questions/2137205/configuring-custom-authorization-with-elmah (ELMAH FAQ's Good Link)

http://ebanshi.cc/questions/3102287/reading-writing-elmah-log-information-from-into-a-custom-table (Elmah Code available on this link)

 

Saturday, July 30, 2016

Writing async code in C# /URL to write C# application online and test them



 using System;
using System.Threading.Tasks;
using System.Net.Http;

public class AsyncSample
{
    static void Main()
    {
        GetURL().Wait();
    }

    private static async Task GetURL()
    {
        HttpClient client = new HttpClient();

        // This code executed asynchronously
        string response =
            await client.GetStringAsync(
            "http://jsonplaceholder.typicode.com/posts/1");

        // This code executed after
        // asynchronous code finalizes
        Console.WriteLine(response);
    }
}

https://www.microsoft.com/net

Microsoft Active Directory Code Snippet

Authenticating an Active Directory user:-

public bool IsUserAuthenticated (string strAdPath, string strDomain, string strUserName, string strPassword)
{
    DirectoryEntry directoryEntry = new DirectoryEntry(string strAdPath, string strDomain+@"\"+strUserName,strPassword);

    Object obj = directoryEntry.NativeObject;
    DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry);
    directorySearch.Filter ="(SAMAccountName = " + strUserName + ")";
    directorySearch.PropertiesToLoad.Add("cn");
    SearchResult searchResult = directorySearch.FindOne();

    if (searchResult ==null)
    {
      return false; // not authenticated
    }
    else
    {
      return true; // authenticated
    }




Searching from Active Directory Server:-

public string[] SearchAD(string strLdapPath, string strCN, string strDomainName,string strSearchFilter)
{
     ArrayList arrayStrList = new ArrayList()
     string[] strSearch= new string[0];
     int i = 0;
     string strLdapString = strLdapPath+ "/CN="+strCN+";DC="+strDomainName;
     DirectoryEntry directoryEntry = new DirectoryEntry (strLdapString);
     DirectorySearcher directorySearcher = new DirectorySearcher (directoryEntry);
     directorySearch.Filter = strSearchFilter;
     foreach (SearchResult sr in directorySearcher.FindAll())
     {
         arrayStrList.Add(sr.GetDirectoryEntry().Path);
         i++;
     }
     strSearch = (string[])arrayStrList.ToArray(typeof(string));
     return strSearch;
}
  

Reading LDAP properties:-

public string[] GetLdapProperties(string strLdapPath, string strCN, string strDomainName)
{
    ArrayList arrayStrList = new ArrayList()
    string[] strProperties = new string[0];
    int i = 0;
    string strLdapString = strLdapPath+ "/CN="+strCN+";DC="+strDomainName;
    DirectoryEntry directoryEntry = new DirectoryEntry (strLdapString);
     foreach (string strProperty in directoryEntry.Properties.PropertyNames)
     {
         arrayStrList.Add(strProperty);
         i++;
     }
     strProperties = (string[])arrayStrList.ToArray(typeof(string));
     return strProperties;


Reference Link:-

http://it.toolbox.com/blogs/programming-life/integrating-your-net-app-with-active-directory-server-8655 

https://support.microsoft.com/en-us/kb/316748 

https://msdn.microsoft.com/en-us/library/ff649227.aspx 

https://msdn.microsoft.com/en-us/library/ff650307.aspx 

Sunday, July 17, 2016

passing multiple lists to model in asp.net mvc 5

Introduction
In MVC we cannot pass multiple models from a controller to the single view. This article provides a workaround for multiple models in a single view in MVC.

Problem Statement
Suppose I have two models, Teacher and Student, and I need to display a list of teachers and students within a single view. How can we do this?

The following are the model definitions for the Teacher and Student classes.
public class Teacher{
    public int TeacherId { get; set; }
    public string Code { get; set; }
    public string Name { get; set; }
public class Student{
    public int StudentId { get; set; }
    public string Code { get; set; }
    public string Name { get; set; }
    public string EnrollmentNo { get; set; }
}
The following are the methods that help us to get all the teachers and students.
private List<Teacher> GetTeachers(){
    List<Teacher> teachers = new List<Teacher>();
    teachers.Add(new Teacher { TeacherId = 1, Code = "TT", Name = "Tejas Trivedi" });
    teachers.Add(new Teacher { TeacherId = 2, Code = "JT", Name = "Jignesh Trivedi" });
    teachers.Add(new Teacher { TeacherId = 3, Code = "RT", Name = "Rakesh Trivedi" });
    return teachers;
public List<Student> GetStudents(){
    List<Student> students = new List<Student>();
    students.Add(new Student { StudentId = 1, Code = "L0001", Name = "Amit Gupta", EnrollmentNo = "201404150001" });
    students.Add(new Student { StudentId = 2, Code = "L0002", Name = "Chetan Gujjar", EnrollmentNo = "201404150002" });
    students.Add(new Student { StudentId = 3, Code = "L0003", Name = "Bhavin Patel", EnrollmentNo = "201404150003" });
    return students;
}
Required output
output

Solution
There are many ways to use multiple models with a single view. Here I will explain ways one by one.

1. Using Dynamic Model

ExpandoObject (the System.Dynamic namespace) is a class that was added to the .Net Framework 4.0 that allows us to dynamically add and remove properties onto an object at runtime. Using this ExpandoObject, we can create a new object and can add our list of teachers and students into it as a property. We can pass this dynamically created object to the view and render list of the teacher and student.

Controller Code
public class HomeController : Controller{
    public ActionResult Index()
    {
        ViewBag.Message = "Welcome to my demo!";
        dynamic mymodel = new ExpandoObject();
        mymodel.Teachers = GetTeachers();
        mymodel.Students = GetStudents();
        return View(mymodel);
    }
}
We can define our model as dynamic (not a strongly typed model) using the @model dynamic keyword.

View Code
@using MultipleModelInOneView;
@model dynamic
@{
    ViewBag.Title = "Home Page";
}
<h2>@ViewBag.Message</h2>

<p><b>Teacher List</b></p>

<table>
    <tr>
        <th>Id</th>
        <th>Code</th>
        <th>Name</th>
    </tr>
    @foreach (Teacher teacher in Model.Teachers)
    {
        <tr>
            <td>@teacher.TeacherId</td>
            <td>@teacher.Code</td>
            <td>@teacher.Name</td>
        </tr>
    }
</table>

<p><b>Student List</b></p>

<table>
    <tr>
        <th>Id</th>
        <th>Code</th>
        <th>Name</th>
        <th>Enrollment No</th>
    </tr>
    @foreach (Student student in Model.Students)
    {
        <tr>
            <td>@student.StudentId</td>
            <td>@student.Code</td>
            <td>@student.Name</td>
            <td>@student.EnrollmentNo</td>
        </tr>
    }
</table>
2. Using View Model
ViewModel is nothing but a single class that may have multiple models. It contains multiple models as a property. It should not contain any method.

In the above example, we have the required View model with two properties. This ViewModel is passed to the view as a model. To get intellisense in the view, we need to define a strongly typed view.
public class ViewModel{
    public IEnumerable<Teacher> Teachers { get; set; }
    public IEnumerable<Student> Students { get; set; }
}
Controller code
public ActionResult IndexViewModel(){
    ViewBag.Message = "Welcome to my demo!";
    ViewModel mymodel = new ViewModel();
    mymodel.Teachers = GetTeachers();
    mymodel.Students = GetStudents();
    return View(mymodel);
}
View code
@using MultipleModelInOneView;@model ViewModel @{    ViewBag.Title = "Home Page";}<h2>@ViewBag.Message</h2> <p><b>Teacher List</b></p> <table>    <tr>        <th>Id</th>        <th>Code</th>        <th>Name</th>    </tr>    @foreach (Teacher teacher in Model.Teachers)
    {
        <tr>            <td>@teacher.TeacherId</td>            <td>@teacher.Code</td>            <td>@teacher.Name</td>        </tr>    }
</table> <p><b>Student List</b></p> <table>    <tr>        <th>Id</th>        <th>Code</th>        <th>Name</th>        <th>Enrollment No</th>    </tr>    @foreach (Student student in Model.Students)
    {
        <tr>            <td>@student.StudentId</td>            <td>@student.Code</td>            <td>@student.Name</td>            <td>@student.EnrollmentNo</td>        </tr>    }
</table>
3. Using ViewData
ViewData is used to transfer data from the controller to the view. ViewData is a dictionary object that may be accessible using a string as the key. Using ViewData, we can pass any object from the controller to the view. The Type Conversion code is required when enumerating in the view.
For the preceding example, we need to create ViewData to pass a list of teachers and students from the controller to the view.

Controller Code
public ActionResult IndexViewData(){
    ViewBag.Message = "Welcome to my demo!";
    ViewData["Teachers"] = GetTeachers();
    ViewData["Students"] = GetStudents();
    return View();
}
View Code
@using MultipleModelInOneView;@{    ViewBag.Title = "Home Page";}<h2>@ViewBag.Message</h2> <p><b>Teacher List</b></p> @{
   IEnumerable<Teacher> teachers = ViewData["Teachers"] as IEnumerable<Teacher>;
   IEnumerable<Student> students = ViewData["Students"] as IEnumerable<Student>;
}<table>    <tr>        <th>Id</th>        <th>Code</th>        <th>Name</th>    </tr>    @foreach (Teacher teacher in teachers)
    {
        <tr>            <td>@teacher.TeacherId</td>            <td>@teacher.Code</td>            <td>@teacher.Name</td>        </tr>    }
</table> <p><b>Student List</b></p>
<table>    <tr>        <th>Id</th>        <th>Code</th>        <th>Name</th>        <th>Enrollment No</th>    </tr>    @foreach (Student student in students)
    {
        <tr>            <td>@student.StudentId</td>            <td>@student.Code</td>            <td>@student.Name</td>            <td>@student.EnrollmentNo</td>        </tr>    }
</table>
4. Using ViewBag
ViewBag is similar to ViewData and is also used to transfer data from the controller to the view. ViewBag is a dynamic property. ViewBag is just a wrapper around the ViewData.

Controller Code
public ActionResult IndexViewBag()
{
    ViewBag.Message = "Welcome to my demo!";
    ViewBag.Teachers = GetTeachers();
    ViewBag.Students = GetStudents();
    return View();
}
View Code
@using MultipleModelInOneView;
@{
    ViewBag.Title = "Home Page";
}
<h2>@ViewBag.Message</h2>

<p><b>Teacher List</b></p>

<table>
    <tr>
        <th>Id</th>
        <th>Code</th>
        <th>Name</th>
    </tr>
    @foreach (Teacher teacher in ViewBag.Teachers)
    {
        <tr>
            <td>@teacher.TeacherId</td>
            <td>@teacher.Code</td>
            <td>@teacher.Name</td>
        </tr>
    }
</table>

<p><b>Student List</b></p>

<table>
    <tr>
        <th>Id</th>
        <th>Code</th>
        <th>Name</th>
        <th>Enrollment No</th>
    </tr>
    @foreach (Student student in ViewBag.Students)
    {
        <tr>
            <td>@student.StudentId</td>
            <td>@student.Code</td>
            <td>@student.Name</td>
            <td>@student.EnrollmentNo</td>
        </tr>
    }
</table>
5. Using Tuple
A Tuple object is an immutable, fixed-size and ordered sequence object. It is a data structure that has a specific number and sequence of elements. The .NET framework supports tuples up to seven elements.

Using this tuple object we can pass multiple models from the controller to the view.

Controller Code
public ActionResult IndexTuple(){
    ViewBag.Message = "Welcome to my demo!";
    var tupleModel = new Tuple<List<Teacher>, List<Student>>(GetTeachers(), GetStudents());
    return View(tupleModel);
}
View Code
@using MultipleModelInOneView;@model Tuple <List<Teacher>, List <Student>>@{    ViewBag.Title = "Home Page";}<h2>@ViewBag.Message</h2> <p><b>Teacher List</b></p><table>    <tr>        <th>Id</th>        <th>Code</th>        <th>Name</th>    </tr>    @foreach (Teacher teacher in Model.Item1)
    {
        <tr>            <td>@teacher.TeacherId</td>            <td>@teacher.Code</td>            <td>@teacher.Name</td>        </tr>    }
</table>
<p><b>Student List</b></p>
<table>    <tr>        <th>Id</th>        <th>Code</th>        <th>Name</th>        <th>Enrollment No</th>    </tr>    @foreach (Student student in Model.Item2)
    {
        <tr>            <td>@student.StudentId</td>            <td>@student.Code</td>            <td>@student.Name</td>            <td>@student.EnrollmentNo</td>        </tr>    }
</table>
6. Using Render Action Method
A Partial View defines or renders a partial view within a view. We can render some part of a view by calling a controller action method using the Html.RenderAction method. The RenderAction method is very useful when we want to display data in the partial view. The disadvantages of this method is that there are only multiple calls of the controller.

In the following example, I have created a view (named partialView.cshtml) and within this view I called the html.RenderAction method to render the teacher and student list.

Controller Code
public ActionResult PartialView()
{
    ViewBag.Message = "Welcome to my demo!";
    return View();
}

/// <summary>
/// Render Teacher List
/// </summary>
/// <returns></returns>
public PartialViewResult RenderTeacher()
{
    return PartialView(GetTeachers());
}

/// <summary>
/// Render Student List
/// </summary>
/// <returns></returns>
public PartialViewResult RenderStudent()
{
    return PartialView(GetStudents());
}
View Code
@{   ViewBag.Title = "PartialView";<h2>@ViewBag.Message</h2><div>    @{        Html.RenderAction("RenderTeacher");
        Html.RenderAction("RenderStudent");
    }
</div>
RenderTeacher.cshtml
@using MultipleModelInOneView;@model IEnumerable<MultipleModelInOneView.Teacher>
 
<p><b>Teacher List</b></p><table>    <tr>        <th>Id</th>        <th>Code</th>        <th>Name</th>    </tr>    @foreach (Teacher teacher in Model)
    {
        <tr>            <td>@teacher.TeacherId</td>            <td>@teacher.Code</td>            <td>@teacher.Name</td>        </tr>    }
</table>
RenderStudent.cshtml
@using MultipleModelInOneView;@model IEnumerable<MultipleModelInOneView.Student
<p><b>Student List</b></p><table>    <tr>        <th>Id</th>        <th>Code</th>        <th>Name</th>        <th>Enrollment No</th>    </tr>    @foreach (Student student in Model)
    {
        <tr>            <td>@student.StudentId</td>            <td>@student.Code</td>            <td>@student.Name</td>            <td>@student.EnrollmentNo</td>        </tr>    }
</table>
Conclusion This article helps us to learn how to pass multiple models from the controller to the view. I hope this will be helpful for beginners.
Reference :-
http://www.c-sharpcorner.com/UploadFile/ff2f08/multiple-models-in-single-view-in-mvc/ --Super Link..