public async Task <BaseResponse> InsertUser(ModelUserView model) { BaseResponse response = new BaseResponse(); using (var dbcxtransaction = await _context.Database.BeginTransactionAsync()) { try { if (_context.MasterUser.Where(n => n.Email == model.Email || n.UserName == model.UserName).Count() == 0) { MasterUser newUser = new MasterUser { UserName = model.UserName, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Password = model.Password, RoleId = model.RoleId, Gender = model.Gender, Age = model.Age, CreatedDate = DateTime.Now, CreatedBy = model.UserName, ModifiedDate = DateTime.Now, ModifiedBy = model.UserName, IsDelete = false }; await _context.MasterUser.AddAsync(newUser); await _context.SaveChangesAsync(); dbcxtransaction.Commit(); response = ResponseConstant.SAVE_SUCCESS; } else { response.Code = (int)HttpStatusCode.BadRequest; response.Status = HttpStatusCode.BadRequest.ToString(); response.Message = "Email already exist."; dbcxtransaction.Rollback(); } } catch (Exception ex) { response.Message = ex.ToString(); response.Code = (int)HttpStatusCode.InternalServerError; response.Status = HttpStatusCode.InternalServerError.ToString(); dbcxtransaction.Rollback(); } } return(response); }
public async Task <IActionResult> Register(ModelUserView model) { var isUsernameExist = await _votingService.GetAsync(_configuration.GetValue <string>("VotingEndPoint:GetUserByUsernameOrEmail") + "/?key=" + model.UserName); var isEmailExist = await _votingService.GetAsync(_configuration.GetValue <string>("VotingEndPoint:GetUserByUsernameOrEmail") + "/?key=" + model.Email); if (isUsernameExist.Data != null) { ModelState.AddModelError("Username", "Username already taken"); } if (isEmailExist.Data != null) { ModelState.AddModelError("Email", "Your Email already registered"); } try { if (ModelState.IsValid) { model.Password = EncryptionHelper.Encrypt(model.Password); model.RoleId = (int)_votingService.GetAsync(_configuration.GetValue <string>("VotingEndPoint:GetRoleId") + "/?key=" + "Voter").Result.Data; var response = await _votingService.PostAsync(_configuration.GetValue <string>("VotingEndPoint:InsertUser"), model); if (response.Code == (int)HttpStatusCode.OK) { TempData["RegisterSuccess"] = "Register Success. Please login !!"; return(RedirectToAction(nameof(Login))); } else { ViewData["GlobalErrorMessage"] = response.Message; return(View(model)); } } } catch (Exception ex) { ViewData["GlobalErrorMessage"] = ex.Message; return(View(model)); } return(View(model)); }
public async Task <BaseResponse> InsertUser([FromBody] ModelUserView model) { return(await _userRepository.InsertUser(model)); }
public IActionResult Register() { ModelUserView model = new ModelUserView(); return(View(model)); }