public async Task <IActionResult> Register(AddUserViewMadel model) { if (ModelState.IsValid) { var role = "Owner"; if (model.RoleId == 1) { role = "Lessee"; } var user = await _userHelper.AddUser(model, role); if (user == null) { ModelState.AddModelError(string.Empty, "This email is already used."); return(View(model)); } if (model.RoleId == 1) { var lessee = new Lesse { Contracts = new List <Contract>(), User = user }; _dataContext.Lesses.Add(lessee); } else { var owner = new Owner { User = user, Contracts = new List <Contract>(), Properties = new List <Property>() }; _dataContext.Owners.Add(owner); } await _dataContext.SaveChangesAsync(); var loginviewModel = new LoginViewModel { Password = model.Password, RememberMe = false, Username = model.username }; var result2 = await _userHelper.LoginAsync(loginviewModel); if (result2.Succeeded) { return(RedirectToAction("Index", "Home")); } } model.Roles = _combosHelper.GetComboRoles(); return(View(model)); }
private LesseeResponse ToLessesResponse(Lesse lessee) { return(new LesseeResponse { Id = lessee.Id, Address = lessee.User.Address, Document = lessee.User.Document, Email = lessee.User.Email, FirstName = lessee.User.FirstName, LastName = lessee.User.LastName, PhoneNumber = lessee.User.PhoneNumber }); }