public IActionResult Put([FromBody] TestWithScales test) { if (_dbContext.Tests.Any(te => te.Name == test.Name)) { return(new StatusCodeResult(409)); } var testEntity = test.ToEntity(_dbContext); _dbContext.Tests.Add(testEntity); _dbContext.SaveChanges(); return(Ok()); }
public IActionResult Add([FromBody] User user) { bool loginIsUsed = _dbContext.Users .Any(userEntity => userEntity.Login == user.Login); if (loginIsUsed) { return(new StatusCodeResult(409)); } _dbContext.Users.Add(user.ToEntity(_dbContext)); _dbContext.SaveChanges(); return(Ok()); }
public IActionResult Post([FromBody] UserRegistrationData userRegistrationData) { if (_dbContext.Users.Any(ue => ue.Login == userRegistrationData.Login)) { return(new StatusCodeResult(409)); } var userEntity = userRegistrationData.ToUserEntity(_dbContext); _dbContext.Users.Add(userEntity); _dbContext.SaveChanges(); return(Ok(new { userId = userEntity.Id })); }