public async Task <IActionResult> Create(AccountModelView mv) { if (ModelState.IsValid) { string extension = Path.GetExtension(mv.Photo.FileName); string imageName = mv.Photo.FileName + Guid.NewGuid() + extension; if (mv.Photo != null) { string path = Path.Combine(Path.Combine(_hostingEnvironment.WebRootPath, "UserImages"), imageName); mv.Photo.CopyTo(new FileStream(path, FileMode.Create)); } var user = new ApplicationUser { UserName = mv.Email, Email = mv.Email, Name = mv.Name, Photo = imageName, PhoneNumber = mv.PhoneNumber, AccountType = mv.AccountType, Location = mv.Location, IdCardNumber = mv.IdCardNumber, WorkPostion = mv.WorkPostion }; var result = await _userManager.CreateAsync(user, mv.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, mv.Role); ModelState.Clear(); ViewBag.alertMsg = "تمت ألعملية بنجاح"; } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } ViewBag.roles = _roleManager.Roles; return(View()); }
public ActionResult Create(AccountModelView add) { if (ModelState.IsValid) { db = new AccountDAL(); User user = new User(); user.Name = add.Name; user.Username = add.Username; user.Email = add.Email; user.Addrress = add.Address; user.Mobile = add.Phone; string seretKey = Utility.RandomString(8); user.UPassword = Securities.EncryptPassword(add.Password + seretKey); int rs = db.Insert(user); switch (rs) { case 1: ViewData["SuccessMsg"] = "Thêm thành công!"; break; case 0: ViewData["ErrorMsg"] = "Thêm không thành công!"; break; case 2: ViewData["ErrorMsg"] = "Thêm không thành công, Tài khoản bị trùng!"; break; default: ViewData["ErrorMsg"] = "Thêm không thành công, Có phát sinh lỗi!"; break; } string btnAction = Request.Form["btnSave"].ToString(); if (btnAction == "SaveAndCreate") { return(RedirectToAction("Create")); } return(RedirectToAction("Index")); } return(View(add)); }
private void btn_Register_Click(object sender, RoutedEventArgs e) { AccountModelView account = new AccountModelView(); account.Username = txt_User.Text; account.Password = teCrypt.Instance.EncryptString(txt_Password.Text, txt_Key.Text); teLogIn.JsonFile.Instance.CreateFile(account); this.DialogResult = true; Close(); }