public ActionResult AddClient(RegisterClientModel model) { ViewBag.RegisterSucess = ""; if (ModelState.IsValid) { try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); Roles.AddUserToRole(model.UserName, "Client"); context.ClientSet.Add(new Client() { FirstName = model.FirstName, LastName = model.LastName, MiddleName = model.MiddleName, Adress = model.Adress, BirthDay = model.BirthDay, User = context.UserSet.First(x => x.UserName == model.UserName) }); context.SaveChanges(); ViewBag.RegisterSucess = "Клиент зарегистрирован"; return(View()); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } return(View(model)); }
public async Task <IHttpActionResult> Register(RegisterClientModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var client = new Client { UserName = model.Email, Email = model.Email, Name = model.Name, Address = model.Address, Location = model.Location }; IdentityResult result; var existingUser = await _userManager.FindByEmailAsync(client.Email); if (existingUser != null) { result = IdentityResult.Failed(new[] { "User with this email already exists" }); } else { result = await _clientManager.CreateAsync(client, model.Password); } if (!result.Succeeded) { return(GetErrorResult(result)); } return(Ok()); }
public async Task <HttpResponseMessage> Post(RegisterClientModel model) { // Check whether user with same e-mail already exists DomainUser user = null; try { user = await _userService.FindByEmailAsync(model.Email); } catch (NotFoundException) { } if (user != null) { return(Request.CreateErrorResponse(HttpStatusCode.Conflict, ResponseMessages.EntityAlreadyExists)); } // Add pending client DomainPendingClient client = await _pendingClientService.AddAsync(model); // Send activation e-mail try { await _emailNotificationService.SendClientActivationEmailAsync(client); } catch (Exception e) { Trace.TraceError("Failed to send registration e-mail to client {0}: {1}", client.Id, e); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public ActionResult RegisterClient(RegisterClientModel model) { if (ModelState.IsValid) { try { Random r = new Random(); int randNum = r.Next(10000); string sixDigitPin = randNum.ToString("D4"); string encodePin = SaccoChapChap.Services.DAL.EncodePassword(sixDigitPin); string strCheckSUM = string.Concat(model.ClientID, model.FirstName, model.OtherNames); strCheckSUM = string.Concat(strCheckSUM, model.Email != null ? model.Email.ToString() : String.Empty); strCheckSUM = string.Concat(strCheckSUM, model.Mobile, model.Remarks != null ? model.Remarks.ToString() : String.Empty); strCheckSUM = string.Concat(strCheckSUM, User.Identity.Name); string strCheckSumHash = SaccoChapChap.Services.DAL.GetCheckSum(strCheckSUM); List <ClientListModel> userlist = _db.Query <ClientListModel>(";Exec CreateClient @ClientID,@FirstName,@OtherNames,@Password,@Email,@Mobile,@Remarks,@CreatedBy,@CheckSumID", new { ClientID = model.ClientID, FirstName = model.FirstName, OtherNames = model.OtherNames, Password = encodePin, Email = model.Email, Mobile = model.Mobile, Remarks = model.Remarks, CreatedBy = User.Identity.Name, CheckSumID = strCheckSumHash }).ToList(); TempData["Success"] = "Client Saved Successfuly!"; return(RedirectToAction("ClientRegister")); //return Json(new { Result = "OK", Record = userlist}); } catch (Exception e) { ViewData["Error"] = e.Message; return(View("ClientRegister", model)); } } else { var message = string.Join(" | ", ModelState.Values .SelectMany(v => v.Errors) .Select(e => e.ErrorMessage)); ViewData["Error"] = message; return(View("ClientRegister", model)); } }
public void CheckSucessfulRegister() { // Arrange RegisterClientModel rcm = new RegisterClientModel(); rcm.EmployeeID = 3; rcm.FirstName = "sean"; rcm.LastName = "paul"; rcm.LoginEmail = "*****@*****.**"; rcm.Password = "******"; rcm.Department = "IT Ops"; rcm.JoiningDate = DateTime.Now; // Act string test = rcm.RegisterClient(); // Assert Assert.AreEqual(test, "Success"); }
public async Task <IActionResult> RegisterClientAsync([FromBody] RegisterClientModel clientModel) { return(this.Ok(await this.CoreRepository.AddClientAsync(clientModel.Name, clientModel.EntityId))); }