Skip to content

Commit 629141a

Browse files
author
Mitchell Marsh
committed
Upload files almost done.
1 parent b96e67e commit 629141a

File tree

9 files changed

+562
-20
lines changed

9 files changed

+562
-20
lines changed

3DPrintingBlockchainMarket/Controllers/AccountController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,20 @@ public async Task<JsonResult> Login(LoginViewModel model)
201201

202202
[HttpPost]
203203
[AllowAnonymous]
204-
[ValidateAntiForgeryToken]
205-
public async Task<JsonResult> Register(RegisterViewModel model)
204+
public async Task<JsonResult> Register([FromBody]RegisterViewModel model)
206205
{
207206
if (ModelState.IsValid)
208207
{
209-
var user = new ApplicationUser { UserName = model.email, Email = model.email };
210-
var result = await _userManager.CreateAsync(user, model.password);
208+
var user = new ApplicationUser { UserName = model.email, Email = model.email, FirstName = model.first_name, LastName = model.last_name };
209+
IdentityResult result = null;
210+
result = await _userManager.CreateAsync(user, model.password);
211211
if (result.Succeeded)
212212
{
213213
_logger.LogInformation("User created a new account with password.");
214214

215215
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
216216
var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
217-
await _emailSender.SendEmailConfirmationAsync(model.email, callbackUrl);
217+
//await _emailSender.SendEmailConfirmationAsync(model.email, callbackUrl);
218218

219219
await _signInManager.SignInAsync(user, isPersistent: false);
220220
_logger.LogInformation("User created a new account with password.");

3DPrintingBlockchainMarket/Controllers/AddModelController.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using _3DPrintingBlockchainMarket.Models.Json;
2+
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Mvc;
24
using System;
35
using System.Collections.Generic;
6+
using System.IO;
47
using System.Linq;
58
using System.Threading.Tasks;
69

@@ -14,6 +17,48 @@ public AddModelController()
1417

1518
}
1619

20+
public async Task<JsonResult> UploadModelAsync(List<IFormFile> files)
21+
{
22+
long size = files.Sum(f => f.Length);
23+
24+
// full path to file in temp location
25+
var filePath = Path.GetTempFileName();
26+
27+
foreach (var formFile in files)
28+
{
29+
if (formFile.Length > 0)
30+
{
31+
using (var stream = new FileStream(filePath, FileMode.Create))
32+
{
33+
await formFile.CopyToAsync(stream);
34+
}
35+
}
36+
}
37+
38+
// process uploaded files
39+
// Don't rely on or trust the FileName property without validation.
40+
41+
return Json(new { result = "Success", message = $"We received {files.Count} File{((files.Count > 0) ? "s" : "")}"});
42+
}
43+
44+
public JsonResult ConfirmValidModel(UploadModelJson model)
45+
{
46+
if(String.IsNullOrEmpty(model.model_license_id)||
47+
String.IsNullOrEmpty(model.name) ||
48+
model.tags.Count == 0 ||
49+
String.IsNullOrEmpty(model.description))
50+
{
51+
//Failed the validation
52+
JsonResult res = Json(new { result = "Failure", reason = "Model does not contain all the proper inforation" });
53+
res.StatusCode = 406;
54+
return res;
55+
}
56+
else
57+
{
58+
//Save the model in the database, allow for upload
59+
}
60+
throw new NotImplementedException();
61+
}
1762

1863
}
1964
}

3DPrintingBlockchainMarket/Controllers/HomeController.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,25 @@
55
using System.Threading.Tasks;
66
using Microsoft.AspNetCore.Mvc;
77
using _3DPrintingBlockchainMarket.Models;
8+
using _3DPrintingBlockchainMarket.Models.AccountViewModels;
9+
using _3DPrintingBlockchainMarket.Models.Json;
810

911
namespace _3DPrintingBlockchainMarket.Controllers
1012
{
1113
public class HomeController : Controller
1214
{
1315
public JsonResult Index()
1416
{
15-
return Json(new { page = "Home", result = "Success" });
17+
UploadModelJson model = new UploadModelJson()
18+
{
19+
description = "description",
20+
model_license_id = "1232-GDEGE43FE43-Ff-vw2gf2...",
21+
name = "My Model",
22+
pricing_unit_of_measure_id = "USD",
23+
tags = new List<string>() { "Green", "Round", "Bouncy" },
24+
token_price = 0
25+
};
26+
return Json(model);
1627
}
1728

1829
public JsonResult About()

0 commit comments

Comments
 (0)