Skip to content

Instantly share code, notes, and snippets.

View talkingdotnet's full-sized avatar

Talking Dotnet talkingdotnet

View GitHub Profile
public void ConfigureServices(IServiceCollection services)
{
// Use Entity Framework in-memory provider for this sample
services.AddDbContext<ToDoListContext>(options => options.UseInMemoryDatabase("ToDoList"));
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
public class ToDoListContext : DbContext
{
public ToDoListContext(DbContextOptions<ToDoListContext> options) : base(options) { }
public DbSet<ToDoList> ToDoLists { get; set; }
}
public class ToDoList
{
public int ID { get; set; }
public string Item { get; set; }
}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { NavMenuComponent } from './nav-menu/nav-menu.component';
import { HomeComponent } from './home/home.component';
import { CounterComponent } from './counter/counter.component';
<li [routerLinkActive]='["link-active"]'>
<a [routerLink]='["/upload"]' (click)='collapse()'>
<span class='glyphicon glyphicon-upload'></span> Upload
</a>
</li>
<h1>File Upload Using Angular 5 and ASP.NET Core 2.1</h1>
<input #file type="file" multiple (change)="upload(file.files)" />
<br/>
<span style="font-weight:bold;color:green;" *ngIf="progress > 0 && progress < 100">
{{progress}}%
</span>
<span style="font-weight:bold;color:green;" *ngIf="message">
{{message}}
</span>
import { Component } from '@angular/core';
import { HttpClient, HttpRequest, HttpEventType, HttpResponse } from '@angular/common/http'
@Component({
selector: 'upload-component',
templateUrl: './upload.component.html'
})
export class UploadComponent {
public progress: number;
public message: string;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using System.IO;
using System.Net.Http.Headers;
namespace Angular5FileUpload.Controllers
{
[Produces("application/json")]
[Route("api/[controller]")]
public class UploadController : Controller
public class GitHubController : ControllerBase
{
[GitHubWebHook]
public IActionResult GitHub(string id, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
public class DropBoxController : ControllerBase
{
[DropboxWebHook]
public IActionResult Dropbox(string id, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}