public JsonResult Register(RegiserModel model) { MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, email: null, passwordQuestion: null, passwordAnswer: null, isApproved: true, status: out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, true); return(Json(new { success = true })); } else { return(Json(new { success = false })); } }
private string UploadedFile(RegiserModel model) { //Generate File Name for Image, in case some pictures have the same Name or property string uniqueFileName = null; if (model.ImgPic != null) { //Note to Self - For Future Reference (https://docs.microsoft.com/en-us/dotnet/api/system.io.path.combine?view=netcore-3.1) //Get the Images Folder Path string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images"); // A Globally Unique Identifier uniqueFileName = Guid.NewGuid().ToString() + "_" + model.ImgPic.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.ImgPic.CopyTo(fileStream); } } return(uniqueFileName); }
public async Task <IActionResult> _RegisterSection(RegiserModel model) { if (ModelState.IsValid) { //-------------- Save Image to Database //UserImgDb userImg = new UserImgDb(); //using (var memoryStream = new MemoryStream()) //{ // await model.ImgPic.CopyToAsync(memoryStream); // userImg.UserImg = memoryStream.ToArray(); //} //-------------- Save Image to Image Folder in the Web Hosting Enivornment string uniqueFileName = UploadedFile(model); UserImgDb userImg = new UserImgDb { UserImg = uniqueFileName }; bool result = await _repo.CreateUserImgAsync(userImg); if (result) { UserDb user = new UserDb { UserName = model.AccountName, UserEmail = model.AccountEmail, UserAddress = model.AccountAddress, UserCity = model.AccountCity, UserCountry = model.AccountCountry, UserDescription = model.AccountDescription, ImageId = userImg.ImageId }; if (model.IsShop) { user.IsShop = true; } var identityResult = await userManager.CreateAsync(user, model.AccountPassword); if (identityResult.Succeeded) { ViewBag.Set = "You are all Set to LogIn"; // return Request. // return RedirectToAction("Index", "Account"); } else { foreach (IdentityError error in identityResult.Errors) { ModelState.AddModelError("", error.Description); } } } } //return PartialView(""model); // return View("AccountManagement", model); return(View("AccountManagement", new AccountPort { RegiserModel = model })); //return View(model); }