Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@GaProgMan
Last active December 22, 2016 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GaProgMan/7eee417f1cafcb3b8fbba4b77803714c to your computer and use it in GitHub Desktop.
Save GaProgMan/7eee417f1cafcb3b8fbba4b77803714c to your computer and use it in GitHub Desktop.
Code blocks for blog post /2016/12/22/application-types/ ‎
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var filePath = GenerateAReportAndReturnFilePath(Math.PI, Math.E);
// do something with the file path
}
public static double CalculateSomeStuff(double inVarOne,
double inVarTwo)
{
return inVarOne *= Math.Pow(inVarTwo, 2);
}
public static bool CheckSomeFileSystemThing(string filePath)
{
return File.Exists(filePath);
}
public static string GenerateAReportAndReturnFilePath(double inVarOne,
double inVarTwo)
{
// do some file generation
var generatedFileName = $"Financials Report - {DateTime.Now.ToString("dd-MM-yyyy")}.pdf";
var totalValue = CalculateSomeStuff(inVarOne,inVarTwo);
if(CheckSomeFileSystemThing(generatedFileName)
{
return Path.Combine(directoryFileIsIn, fileName);
}
}
}
}
using Reporting; //our reporting namespace
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var filePath = FinancialsGenerator
.GenerateAReportAndReturnFilePath(Math.PI, Math.E);
// do something with the file path
}
}
}
using System;
namespace Reporting
{
public static class FinancialsGenerator
{
private static double CalculateSomeStuff(double inVarOne,
double inVarTwo)
{
return inVarOne *= Math.Pow(inVarTwo, 2);
}
private static bool CheckSomeFileSystemThing(string filePath)
{
return File.Exists(filePath);
}
public static string GenerateAReportAndReturnFilePath(double inVarOne,
double inVarTwo)
{
// do some file generation
var generatedFileName = $"Financials Report - {DateTime.Now.ToString("dd-MM-yyyy")}.pdf";
var totalValue = CalculateSomeStuff(inVarOne,inVarTwo);
if(CheckSomeFileSystemThing(generatedFileName)
{
return Path.Combine(directoryFileIsIn, fileName);
}
}
}
}
using System;
namespace Reporting
{
public static class Generator
{
private static double CalculateSomeStuff(double inVarOne,
double inVarTwo)
{
return inVarOne *= Math.Pow(inVarTwo, 2);
}
private static bool CheckSomeFileSystemThing(string filePath)
{
return File.Exists(filePath);
}
}
public static class FinancialsGenerator : Generator
{
public static string GenerateAReportAndReturnFilePath(double inVarOne,
double inVarTwo)
{
// do some file generation
var generatedFileName = $"Financials Report - {DateTime.Now.ToString("dd-MM-yyyy")}.pdf";
var totalValue = CalculateSomeStuff(inVarOne,inVarTwo);
if(CheckSomeFileSystemThing(generatedFileName)
{
return Path.Combine(directoryFileIsIn, fileName);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace mvcApp.Controllers
{
[Authorize(Roles = "SuperAdmin"]
public class MyController : Controller
{
public IActionResult SuperSecretActionMethod()
{
// shh! don't tell the average users
}
[AllowAnonymous]
public IActionResult EveryOneCanAccess()
{
// the difference is that even users who aren't
// logged in can see this ActionMethod
}
}
}
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
[HttpGet("SayHello")]
public string SayHello()
{
return "Hello, world!";
}
// GET api/values/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace webApiApp.Controllers
{
[Route("api/[controller]")]
public class ValuesController : Controller
{
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
public void Post([FromBody]string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseMvc();
}
yo asptnet
dotnet restore
dotnet run
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://localhost:5000/api/Values
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method webApiApp.Controllers.ValuesController.Get (webApiApp) with arguments () - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.Internal.ObjectResultExecutor[1]
Executing ObjectResult, writing value Microsoft.AspNetCore.Mvc.ControllerContext.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action webApiApp.Controllers.ValuesController.Get (webApiApp) in 2.6894ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 5.2741ms 200 application/json; charset=utf-8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment