Skip to content

Instantly share code, notes, and snippets.

View A-Programmer's full-sized avatar

Kamran Sadin A-Programmer

  • Sadin
  • Iran
  • X @MrSadin
View GitHub Profile
@A-Programmer
A-Programmer / SqlQuery
Created March 21, 2017 17:48
Run SQL query with Entity Framework
//Select query
//Table name : MyTable
//In this table i have one field called : PropertyName
using(var db = new MyDbContext())
{
var myData = db.MyTableName.SqlQuery("SELECT * From MyTableName").ToList();
foreach(var data in myData)
{
Response.Write(data.PropertyName + "<br/>");
}
@A-Programmer
A-Programmer / DotNetCore
Created March 23, 2017 20:53
Creating new Empty MVC Project and run it in Visual Studio Code with Dot Net Core
First of all you should install pre requirements:
Install Dot Net Core (http://dot.net/Core)
Install Visual Studio Code
1. Now run Visual Studio Code
2. Press Ctrl + ` (or from View menu select Integrated Terminal)
3. Navigate to folder that you want to create project in it.
4. run this command : dotnet new web (this will create project files in current folder)
5. Open Startup.cs file and edit it :
5.1 Add 'services.AddMvc();' to ConfigureServices void
5.2 Add route to Configure void :
@A-Programmer
A-Programmer / Startup.cs
Created March 24, 2017 19:53
ConfigureServices method
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
@A-Programmer
A-Programmer / PublishDotNetCore
Created March 25, 2017 10:37
Publish DotNet Core Project
For publish .net core project open terminal (command) and navigate to project directory
Then type dotnet publish -o /PublishFolderPath
@A-Programmer
A-Programmer / Cmd.txt
Last active March 26, 2017 15:49
Create directory,delete directory,create file, delete file,copy file
1. Create directory :
mkdir DirectoryName
mkdir MrSadin
2. Navigate to directory :
cd DirectoryName (Or Path)
cd MrSadin
3. Delete Empty Directory : (Attention, directory should be empty)
rmdir DirectoryName
rmdir MrSadin
4. Delete directory that contains some files
@A-Programmer
A-Programmer / Views.cshtml
Created March 27, 2017 02:14
Working with Views
So its time to working with Views
At first create Views folder : mkdir Views
Create Home and Shared folder : mkdir Views\Home mkdir Views\Shared
Creating files :
echo.>Views\_ViewImports.cshtml
echo.>Views\_ViewStart.cshtml
echo.>Views\Shared\_Layout.cshtml
echo.>Views\Home\Index.cshtml
Open Startup.cs and add this line to Configure method :
app.UseStaticFiles();
@A-Programmer
A-Programmer / UsefulLinks.txt
Created March 27, 2017 17:26
Useful linkes about Dot Net Core
@A-Programmer
A-Programmer / UseMySqlInNetCore.txt
Last active March 29, 2017 21:31
How to use MySql database in Dot Net Core Project
0. Create new console app (dotnet new console)
1. Create appsettings.js
2. Add this codes to file :
{
"ConnectionStrings":
{
"SampleConnection": "server=localhost;userid=root;pwd=;port=3305;database=KamranDb3;"
}
}
3. Add this packages using Nuget Package Manager (or just copy this to YourProject.csproj file) :
@A-Programmer
A-Programmer / Models.txt
Last active March 29, 2017 21:32
Adding model and DbContext to .Net Core Project
First of all install vscode-nuget-package-manager Extension.
Open .cspro file
Press Ctrl + Shift + P and type >NuGet Package MAnager: Add Package
Type Microsoft.EntityFrameworkCore.SqlServer
use dotnet restore
Create database 'MyDatabase' and a table called MyModels with 3 fields (Id, FullName,Email)
Add 'Models' folder and 'MyDbContext.cs' and 'MyModel.cs' files in it
Open MyModel.cs and add this codes :
using Microsoft.EntityFrameworkCore;
@A-Programmer
A-Programmer / ImageHelper.cs
Created April 7, 2017 19:58
Some methods for working with images in C#
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
namespace Helpers
{
public class ImageHelper
{
/// <summary>