public RestApiResult Create(JObject json) { if (json == null) { return new RestApiResult { StatusCode = HttpStatusCode.BadRequest } } ; User user = User.FromJson(json); user.CreatedDate = DateTime.Now; if (ClarityDB.Instance.Users.Any(x => x.UserName.ToLower() == user.UserName.ToLower())) { string errorJson = "{ 'error': 'User name exists' }"; return(new RestApiResult { StatusCode = HttpStatusCode.Conflict, Json = JObject.Parse(errorJson) }); } user.Salt = passwordHash.CreateSalt(); user.Password = passwordHash.CreatePasswordHash(user.Password, user.Salt); ClarityDB.Instance.Users.Add(user); ClarityDB.Instance.SaveChanges(); return(new RestApiResult { StatusCode = HttpStatusCode.OK, Json = user.ToJson() }); }