This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ActionResult OnPostImport() | |
{ | |
IFormFile file = Request.Form.Files[0]; | |
string folderName = "Upload"; | |
string webRootPath = _hostingEnvironment.WebRootPath; | |
string newPath = Path.Combine(webRootPath, folderName); | |
StringBuilder sb = new StringBuilder(); | |
if (!Directory.Exists(newPath)) | |
{ | |
Directory.CreateDirectory(newPath); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<IActionResult> OnPostExport() | |
{ | |
string sWebRootFolder = _hostingEnvironment.WebRootPath; | |
string sFileName = @"demo.xlsx"; | |
string URL = string.Format("{0}://{1}/{2}", Request.Scheme, Request.Host, sFileName); | |
FileInfo file = new FileInfo(Path.Combine(sWebRootFolder, sFileName)); | |
var memory = new MemoryStream(); | |
using (var fs = new FileStream(Path.Combine(sWebRootFolder, sFileName), FileMode.Create, FileAccess.Write)) | |
{ | |
IWorkbook workbook; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddSwaggerGen(c => | |
{ | |
c.SwaggerDoc("v1", new Info | |
{ | |
Version = "v1", | |
Title = "My API", | |
Description = "My First ASP.NET Core Web API", | |
Contact = new Contact() { Name = "Talking Dotnet", Email = "[email protected]", Url = "www.talkingdotnet.com" } | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.UseSpa(spa => | |
{ | |
// To learn more about options for serving an Angular SPA from ASP.NET Core, | |
// see https://go.microsoft.com/fwlink/?linkid=864501 | |
spa.Options.SourcePath = "ClientApp"; | |
if (env.IsDevelopment()) | |
{ | |
spa.UseAngularCliServer(npmScript: "start"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.UseSpa(spa => | |
{ | |
// To learn more about options for serving an Angular SPA from ASP.NET Core, | |
// see https://go.microsoft.com/fwlink/?linkid=864501 | |
spa.Options.SourcePath = "ClientApp"; | |
if (env.IsDevelopment()) | |
{ | |
spa.UseProxyToSpaDevelopmentServer("http://localhost:4200"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.UseSpa(spa => | |
{ | |
spa.Options.SourcePath = "ClientApp"; | |
if (env.IsDevelopment()) | |
{ | |
spa.UseReactDevelopmentServer(npmScript: "start"); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!ModelState.IsValid) | |
{ | |
// bad request - Take necessary actions | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ValidateModelStateAttribute : ActionFilterAttribute | |
{ | |
public override void OnActionExecuting(ActionExecutingContext context) | |
{ | |
if (!context.ModelState.IsValid) | |
{ | |
context.Result = new BadRequestObjectResult(context.ModelState); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc(options => | |
{ | |
options.Filters.Add(typeof(ValidateModelStateAttribute)); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class SessionExtensions | |
{ | |
public static void SetObject(this ISession session, string key, object value) | |
{ | |
session.SetString(key, JsonConvert.SerializeObject(value)); | |
} | |
public static T GetObject<T>(this ISession session, string key) | |
{ | |
var value = session.GetString(key); |