public async Task <ActionResult <UserEnterprise> > PostUserEnterprise(UserEnterprise userEnterprise) { _context.UserEnterprise.Add(userEnterprise); await _context.SaveChangesAsync(); return(CreatedAtAction("GetUserEnterprise", new { id = userEnterprise.Id }, userEnterprise)); }
public async Task <IActionResult> PutUserEnterprise(int id, UserEnterprise userEnterprise) { if (id != userEnterprise.Id) { return(BadRequest()); } _context.Entry(userEnterprise).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserEnterpriseExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void UserValidate(UserEnterprise user) { if (user.BirthDate > DateTime.Now) { throw new ArgumentOutOfRangeException("BirthDate"); } if (user.FirstName.Length > 100) { throw new ArgumentOutOfRangeException("FirstName"); } if (user.LastName.Length > 100) { throw new ArgumentOutOfRangeException("LastName"); } if (user.UserName.Length > 100) { throw new ArgumentOutOfRangeException("UserName"); } if (user.Email.Length > 200 || !user.Email.Contains('@')) { throw new ArgumentException("Email"); } if (user.Gender != "M" && user.Gender != "F") { throw new ArgumentException("Gender"); } valid = true; }
public void Save(UserEnterprise userEnterprise) { if (userEnterprise.IsNew()) { Add(userEnterprise); } else { Update(userEnterprise); } }
protected void btnSalvar_Click(object sender, EventArgs e) { UserEnterprise userEnterprise = new UserEnterprise() { IdUser = Convert.ToInt32(DropDownUsers.SelectedValue), IdEnterprise = Convert.ToInt32(DropDownEnterprises.SelectedValue), }; _userEnterpriseRepository.Save(userEnterprise); Response.Redirect("~/"); }
public void ValidUser() { UserEnterprise userEnterprise = new UserEnterprise { FirstName = "Guilherme", LastName = "Correia", UserName = "******", Email = "*****@*****.**", Gender = "M", BirthDate = new DateTime(1993, 10, 30) }; bool expected = true; CadastroUsuario.Controllers.UserEnterprisesController controller = new CadastroUsuario.Controllers.UserEnterprisesController(null); // Act controller.UserValidate(userEnterprise); // Assert Assert.AreEqual(expected, controller.valid, "", "Account not debited correctly"); }
public async Task <ObjectResult> Post(UserEnterprise _userData) { if (_userData != null && _userData.Email != null && _userData.Password != null) { var user = await GetUser(_userData.Email, _userData.Password); if (user != null) { //create claims details based on the user information var claims = new[] { new Claim(JwtRegisteredClaimNames.Sub, _configuration["Jwt:Subject"]), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), new Claim(JwtRegisteredClaimNames.Iat, DateTime.UtcNow.ToString()), new Claim("Id", user.Id.ToString()), new Claim("FirstName", user.FirstName), new Claim("LastName", user.LastName), new Claim("UserName", user.UserName), new Claim("Email", user.Email), new Claim("BirthDate", user.BirthDate.ToShortDateString()), new Claim("Gender", user.Gender) }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["Jwt:Key"])); var signIn = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken(_configuration["Jwt:Issuer"], _configuration["Jwt:Audience"], claims, expires: DateTime.UtcNow.AddDays(1), signingCredentials: signIn); return(Ok(new JwtSecurityTokenHandler().WriteToken(token))); } else { return(BadRequest("Invalid credentials")); } } else { return(BadRequest("Invalid credentials")); } }
private void Update(UserEnterprise userEnterprise) { using (ISession session = FluentSessionFactory.abrirSession()) { using (ITransaction transacao = session.BeginTransaction()) { try { session.Update(userEnterprise); transacao.Commit(); } catch (Exception e) { if (!transacao.WasCommitted) { transacao.Rollback(); } throw new Exception("Erro ao atualizar usuário em empresa: " + e.Message); } } } }