diff --git a/SeniorAssistant/Controllers/AccountController.cs b/SeniorAssistant/Controllers/AccountController.cs index 6a999d4..2c6dce0 100644 --- a/SeniorAssistant/Controllers/AccountController.cs +++ b/SeniorAssistant/Controllers/AccountController.cs @@ -6,6 +6,8 @@ using LinqToDB; using System.Linq; using System; using SeniorAssistant.Models.Users; +using System.Web; +using System.IO; namespace IdentityDemo.Controllers { @@ -61,13 +63,20 @@ namespace IdentityDemo.Controllers } [HttpPost] - public ActionResult _register(User user) + public ActionResult _register(User user, string code = "") { return Action(() => { try { Db.Insert(user); + if(code != null && code.Equals("444442220")) + { + Db.Insert(new Doctor + { + Username = user.Username + }); + }; return _login(user.Username, user.Password); } catch @@ -181,5 +190,49 @@ namespace IdentityDemo.Controllers return Json(OkJson); }); } + + + [HttpPost] + public async System.Threading.Tasks.Task Save(IFormFile file) + { + return LoggedAction(() => + { + var loggedUser = HttpContext.Session.GetString(Username); + if (file.Length > 0) + { + var name = loggedUser + ".jpg"; + var path = Path.Combine(("~/uploads/"), name); + var stream = new FileStream(path, FileMode.Create); + file.CopyTo(stream); + var user = (from u in Db.Users + where u.Username.Equals(loggedUser) + select u).FirstOrDefault(); + user.Avatar = path; + + Db.Update(User); + } + + return Json(OkJson); + }); + + /* + var loggedUser = HttpContext.Session.GetString(Username); + + long size = file.Length; + + // full path to file in temp location + var filePathPart = Path.GetDirectoryName("~/AdminLTE-2.4.3/dist/img/"); + var fileName = Path.GetFileName(loggedUser + ".jpg"); + var filePath = Path.Combine(filePathPart,fileName); + if (size > 0) + { + using (var stream = new FileStream(filePath, FileMode.Create)) + { + await file.CopyToAsync(stream); + } + } + return Json(new JsonResponse()); + */ + } } } \ No newline at end of file diff --git a/SeniorAssistant/Models/Users/User.cs b/SeniorAssistant/Models/Users/User.cs index 98f56ba..54cf019 100644 --- a/SeniorAssistant/Models/Users/User.cs +++ b/SeniorAssistant/Models/Users/User.cs @@ -18,5 +18,7 @@ namespace SeniorAssistant.Models public string Name { get; set; } public string LastName { get; set; } + + public string Avatar { get; set; } } } diff --git a/SeniorAssistant/SeniorAssistant.csproj b/SeniorAssistant/SeniorAssistant.csproj index 3fb5c1f..816b670 100644 --- a/SeniorAssistant/SeniorAssistant.csproj +++ b/SeniorAssistant/SeniorAssistant.csproj @@ -7,7 +7,7 @@ - + diff --git a/SeniorAssistant/Views/Shared/Logout.cshtml b/SeniorAssistant/Views/Shared/Logout.cshtml index f65e781..6de1a21 100644 --- a/SeniorAssistant/Views/Shared/Logout.cshtml +++ b/SeniorAssistant/Views/Shared/Logout.cshtml @@ -14,7 +14,19 @@ + + } } diff --git a/SeniorAssistant/Views/Shared/Register.cshtml b/SeniorAssistant/Views/Shared/Register.cshtml index bbe41f9..069e3f7 100644 --- a/SeniorAssistant/Views/Shared/Register.cshtml +++ b/SeniorAssistant/Views/Shared/Register.cshtml @@ -5,7 +5,7 @@ - +
@@ -20,17 +20,19 @@ var lastname = $("#regLastname").val(); var password = $("#regPassword").val(); var email = $("#regEmail").val(); - var role = $("#regDoctor").is(":checked")? "Doctor":"User"; + var code = $("#regDoctor").val(); $.ajax({ url: "/Account/_register", data: { - Username: username, - Name: name, - Lastname: lastname, - Password: password, - Email: email, - Role: role + Code: code, + User: { + Username: username, + Name: name, + Lastname: lastname, + Password: password, + Email: email + } }, dataType: "json", type: "POST", @@ -43,7 +45,7 @@ } }, error: function (xhr, status, error) { - alert(xhr.responseText) + alert(error) } }) }); diff --git a/SeniorAssistant/libman.json b/SeniorAssistant/libman.json new file mode 100644 index 0000000..ceee271 --- /dev/null +++ b/SeniorAssistant/libman.json @@ -0,0 +1,5 @@ +{ + "version": "1.0", + "defaultProvider": "cdnjs", + "libraries": [] +} \ No newline at end of file diff --git a/SeniorAssistant/senior.db b/SeniorAssistant/senior.db new file mode 100644 index 0000000..32e616b Binary files /dev/null and b/SeniorAssistant/senior.db differ