Friday, December 16, 2016

Find Highest,Lowest and average using two dimensional arrays

//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int[] marks = new int[5]{90,29,100,48,60};
            string[] names = new string[5]{"Bongani","Zesipho","Edward","Thato","Thobela"};
         
            string Hname = null;
            string Lname = null;
            int highest = marks[0];
            int lowest = marks[0];
            int sum =0;
            double average;
            int aboveAvg =0;
            int lessthanAvg= 0;
         
            for(int x = 0;x<marks.Length;x++)
            {
             
                //find highest
                if(marks[x]>highest)
                {
                    highest = marks[x];
                    Hname = names[x];
                }
             
                //Find Lowest
                if(marks[x]<lowest)
                {
                    lowest = marks[x];
                    Lname = names[x];
                }
             
                //Find Average
                sum +=marks[x];
             
             
             
            }
         
            average = sum / marks.Length;
         
            for(int x = 0;x<marks.Length;x++)
            {
                if(marks[x]>average)
                {
                    aboveAvg++;
                }
                else
                {
                    lessthanAvg++;
                }
            }
             
            //PRINTING NECESSARY RESULTS
         
            Console.WriteLine("{0} is the highest with {1}% ",Hname,highest);
            Console.WriteLine("{0} is the lowest with {1}% ",Lname,lowest);
            Console.WriteLine("The Average Mark is {0}%",average);
            Console.WriteLine("Number of Students less than Average is {0}%",aboveAvg);
            Console.WriteLine("Number of Students Above Average is {0}%",lessthanAvg);
         
        }
    }
}
=================
Edward is the highest with 100% 
Zesipho is the lowest with 29% 
The Average Mark is 65%
Number of Students less than Average is 2%
Number of Students Above Average is 3%

Example Deserialize a Json Array using Newtonsoft.Json

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Newtonsoft.Json;

namespace Rextester
{

public class MyClass
{
    public List<Item> data;
}
    public class Item
    {
        public string Comment;
        public string Name;
        public string CreationDate;
        public string Url;
        public string Uuid;
    }
    
    public class Program
    {
        static string json =@"
{
    'data': [
        {
            'comment': '<No comment>',
            'creationDate': '14.07.2016 22:14',
            'name': 'Name version 1',
            'url': 'http:\\\\www.google.com',
            'uuid': '12345'
        },
        {
            'comment': 'Hotfix. ',
            'creationDate': '14.07.2016 22:13',
            'name': 'Name version 2',
            'url': 'http:\\\\www.google.com',
            'uuid': '8888888'
        },
        {
            'comment': 'for test purposes',
            'creationDate': '14.07.2016 13:34',
            'name': 'Name version 3',
            'url': 'http:\\\\www.google.com',
            'uuid': 'hiuhihiuphpuihiuh'
        }
    ]
}
";
        
        public static void Main(string[] args)
        {
            //Your code goes here
            
            MyClass ss = JsonConvert.DeserializeObject<MyClass>(json);
            Console.WriteLine(ss.data[0].Comment);
            
        }
    }
}

StringCompare

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //Your code goes here
       

           string str1="ri", str2 = "si";
         
            var common = str1.Intersect(str2);
         
         
            foreach(var c in common)
            {
                Console.Write(c);
         
            }
         
         

        }

    }

}
=========
i
      

Difference between Code first, Model first & Database first

n this article we are going to discuss difference between Code First, Model First & Data Base First. These are the basic approaches used in Entity Framework.  

Code first

  • popular in hardcore programmers.
  • The database is used for data only.
  • Manual changes to database will be lost because your code defines the database.
  • Full control by code.
Database first

  • Mostly used when Database is already created.
  • If you want additional features in POCO entities you must either T4 modify template or use partial classes.
  • Code is auto generated..
  • The developer can update the database manually.
Model first

  • We can create the database model.
  • Extensible through partial classes
  • Manual changes to database will be most probably lost because your model defines the database.

Thursday, October 27, 2016

Disable Future And Past Date of jQuery Calendar In ASP.NET MVC

$(document).ready(function() { 
    $("#EnterDate").datepicker({ 
        dateFormat:"dd-mm-yy"
        minDate: -0, 
        maxDate: "+0M +0D" 
 
    }); 
});

 ---------------------
 Now let us change the maxDate property to enable only five days from current date
$(document).ready(function() {  
    $("#EnterDate").datepicker({  
        dateFormat:"dd-mm-yy"
        minDate: -0,  
        maxDate: "+0M +4D"  
  
    });  
}); 

Confirm Alert Box on ActionLink Click in ASP.NET MVC

@Html.ActionLink("Delete", "DeleteEmp", new { id = item.Empid },

new { onclick = "return confirm('Are sure wants to delete?');" })
EDMX--ntity Data Model XML

Tuesday, October 25, 2016

Why .net cant become a platform independent language

The CLI (Common Language Infrastructure) is a standard, and as such it is designed to be
mostly platform-independent. Here, platform refers to the underlying computer architecture, including
the operating system.

.NET is Microsoft's principal implementation of the CLI and runs only on Windows systems. Therefore,
.NET is not platform-independent.

Mono is also an implementation of the CLI, but one designed to work on different platforms such as Linux
and Windows. Mono is definitely more platform-independent than .NET.

Why does .NET generate two web.config files in an MVC asp.net application?

Why does .NET generate two web.config files in an MVC asp.net application?
----------
I'd like to add to this that the Web.Config in the /Views folder is a great (if not thé) way to declare namespaces specifically for your views in. In a web application it is very possible almost every view gets a ViewModel (instead of your actual model) passed to it. Declaring the full namespace after @model or having the same @using App.Web.Viewmodels gets tedious. This way, all viewmodels are automatically available and you have to do extra work to get the real models in scope, which should then set of some alarm bells immediatly.

Also, usually an application can get a lot of extension-methods specifically for use in the view (the HTML-helper jumps into mind). It makes sense to define the namespace to this extension class in the /Views/Web.Config. That way you never wonder "Why cant IntelliSense find the @Html.ImageLink() method??!"
-----------------
You can have multiple configuration files in your project at the same level too. We do it like this. We have one main configuration file (Web.Config), then we have two more configurations files. App.Config and Database.Config. in App.Config we defined all the application level settings. in Database.Config we define all the database level settings. And in Web.Config we refer App.Config and Database.Config like this:

 <appSettings configSource="app.config">
 </appSettings>
 <connectionStrings configSource="database.config">
 </connectionStrings>
Also , you can have multiple web.config files in sub directories. Settings will be override automatically by asp.net.

Thursday, October 13, 2016

How to use session in a web service?

Add Customer.cs file...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services; 
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

//To support Session in Web service then session class must be inheited from
//System.Web.Services.WebService
public class Customer : System.Web.Services.WebService
{
    //to Enable session it must to set EnableSession=true
    [WebMethod (EnableSession=true)]
    public int GetAddition(int Number)
    {
        //cekcing wheter the session is null
        if (Session["GetAddition"] == null)
        {
            //set session value to 0 if session is null
            Session["GetAddition"] = 0;      
        }
        else
        {
            //Add the user Input value into the existing session value
            Session["GetAddition"] = (int)Session["GetAddition"] + Number;             
        }
        //returen the session value
        return (int)Session["GetAddition"];
    }    
}
Customer.asmx
<%@ WebService Language="C#" CodeBehind="~/App_Code/Customer.cs" Class="Customer" %>
Default.aspx design
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body style="background-color:Blue">
<h4 style="color:White">Article by Vithal Wadje</h4>
    <form id="form1" runat="server">
    <table style="margin-top:60px;color:White">
    <tr>
    <td>Enter Value</td>
    <td>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
    </tr>
    <tr>
    <td></td><td></td>
    </tr>
     <tr>
    <td></td><td>
        <asp:Button ID="btngetAddition" runat="server" Text="Get Addition"
             onclick="btngetAddition_Click" /> </td>
    </tr>
    <tr>
    <td>
  Addition
    </td>
    <td id="tdoutput" runat="server">
   
    </td>
    </tr>
    </table>
    </form>
</body>
</html>
Default.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    { 
    }
    protected void btngetAddition_Click(object sender, EventArgs e)
    {
        Customer obj = new Customer(); 
        tdoutput.InnerText = Convert.ToString(obj.GetAddition(Convert.ToInt32(TextBox1.Text)));
    }
}
Web.config file
<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>
</configuration>