Skip to content

Instantly share code, notes, and snippets.

View corespider's full-sized avatar
🎯
Focusing

corespider

🎯
Focusing
View GitHub Profile
@corespider
corespider / Common.cs
Created January 6, 2022 05:09
Reverse a String using C# in .NET Core console application
public static class Common
{
internal static string ReverseString(string input)
{
string output = string.Empty;
char[] chars = input.ToCharArray();
for (int i = chars.Length - 1; i >= 0; i--)
{
output += chars[i];
}
@corespider
corespider / Index.cshtml
Created January 5, 2022 17:27
How to use WebGrid in ASP.Net MVC
@using XML_WebGrid_aspnetmvc.Models
@model IEnumerable<Customer>
@{
ViewBag.Title = "Home Page";
WebGrid webGrid = new WebGrid(source: Model, canPage: true, canSort: true);
}
<div class="row">
@webGrid.GetHtml(
htmlAttributes: new { @id = "WebGrid", @class = "table" },
columns: webGrid.Columns(
@corespider
corespider / HomeController.cs
Created January 5, 2022 17:24
How to use WebGrid in ASP.Net MVC
public class HomeController : Controller
{
public ActionResult Index()
{
List<Customer> customers = new List<Customer>();
//Load the XML file in XmlDocument.
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("~/customer.xml"));
@corespider
corespider / Customer.cs
Created January 5, 2022 17:22
How to use WebGrid in ASP.Net MVC
public class Customer
{
public int customerId { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public string email { get; set; }
public string street { get; set; }
public string city { get; set; }
public string state { get; set; }
public string zipCode { get; set; }
@corespider
corespider / customer.xml
Created January 5, 2022 17:20
How to use WebGrid in ASP.Net MVC
<CustomerDetails>
<customer>
<customer_id>1</customer_id>
<first_name>Debra</first_name>
<last_name>Burks</last_name>
<email>debra.burks@yahoo.com</email>
<street>9273 Thorne Ave. </street>
<city>Orchard Park</city>
<state>NY</state>
<zip_code>14127</zip_code>
@corespider
corespider / Program.cs
Created January 4, 2022 16:54
What replaces WCF in .Net Core?
IpcServiceClient<ICalculator> client = new IpcServiceClientBuilder<ICalculator>()
.UseNamedPipe("pipeName") // or .UseTcp(IPAddress.Loopback, 45684) to invoke using TCP
.Build();
int result = await client.InvokeAsync(x => x.Addcalc(12, 15));
@corespider
corespider / Program.cs
Created January 4, 2022 16:51
What replaces WCF in .Net Core?
class Program
{
static void Main(string[] args)
{
// configure DI
IServiceCollection services = ConfigureServices(new ServiceCollection());
// build and run service host
new IpcServiceHostBuilder(services.BuildServiceProvider())
.AddNamedPipeEndpoint<IComputingService>(name: "endpoint1", pipeName: "pipeName")
@corespider
corespider / Calculator.cs
Created January 4, 2022 16:49
What replaces WCF in .Net Core?
class Calculator : ICalculator
{
public int AddFloat(int x, int y)
{
return x + y;
}
}
@corespider
corespider / ICalculator.cs
Created January 4, 2022 16:47
What replaces WCF in .Net Core?
public interface ICalculator
{
int Addcalc(int x, int y);
}
@corespider
corespider / InsertElement.cs
Created January 2, 2022 11:12
How to prevent duplicate(double) Inserts when Page is refreshed in ASP.Net
private void InsertElement()
{
string strQuery = "insert into customers (CustomerID, CompanyName) values (@CustomerID, @CompanyName)";
SqlCommand cmd = new SqlCommand(strQuery);
cmd.Parameters.AddWithValue("@CustomerID", "001");
cmd.Parameters.AddWithValue("@CompanyName", "Google");
InsertUpdateData(cmd);
Response.Redirect(Request.Url.AbsoluteUri);
}