//public async Task<UpdateLoginUsersResponse> Post([FromBody]LoginUsersAddRequest loginuser) public async Task <dynamic> Post([FromBody] LoginUsersAddRequest loginuser) { UpdateLoginUsersResponse registrationResponse = new UpdateLoginUsersResponse(); var response = await _cloudantService.GetAllAsync(DBNames.loginusers.ToString()); BulkData loginusers = JsonConvert.DeserializeObject <BulkData>(response); var IsUserExist = loginusers.rows.FirstOrDefault(a => a.doc.Username == loginuser.Username); if (IsUserExist == null) { if (_postUserLoginProcessor != null) { //return await _postUserLoginProcessor.PostNewUserRecord(loginuser, _cloudantService); HashSalt hashSalt = Helper.GenerateSaltedHash(64, loginuser.Password); loginuser.Password = hashSalt.Hash; loginuser.Passwordsalt = hashSalt.Salt; _postUserLoginProcessor.PostNewUserRecord(loginuser, _cloudantService); return(new string[] { "SUCCESS" }); } else { //return new UpdateLoginUsersResponse(); return(new string[] { "No database connection" }); } } else { return(new string[] { "USER_ALREADY_EXIST" }); } }
public async Task <dynamic> Post([FromBody] LoginUsersAddRequest loginuser) { if (_cloudantService != null) { return(await _cloudantService.CreateAsync(loginuser)); //Console.WriteLine("POST RESULT " + response); //return new string[] { employee.IBMEmailID, employee._id, employee._rev }; //return JsonConvert.DeserializeObject<UpdateEmployeeResponse>(response.Result); } else { return(new string[] { "No database connection" }); } }
public async Task <UpdateLoginUsersResponse> PostNewUserRecord(LoginUsersAddRequest loginuserAddRequest, ICloudantService cloudantService = null) { //AuditData auditData = new AuditData(); //auditData.eventname = "Add"; //auditData.loginid = loginuserAddRequest.loginid; //auditData.datetime = System.DateTime.UtcNow.ToString(); //auditData.empid = employeeAddRequest.FormattedEmployeedId; if (cloudantService != null) { var response = await cloudantService.CreateAsync(loginuserAddRequest, DBNames.loginusers.ToString()); // var audit = await cloudantService.CreateAsync(auditData, DBNames.auditdata.ToString()); return(JsonConvert.DeserializeObject <UpdateLoginUsersResponse>(response)); } else { return(new UpdateLoginUsersResponse()); } }
public async Task <dynamic> CreateAsync(LoginUsersAddRequest item) { string jsonInString = JsonConvert.SerializeObject(item); var _client = _factory.CreateClient("cloudant"); var response = await _client.PostAsync(_client.BaseAddress + _dbName, new StringContent(jsonInString, Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { var responseJson = await response.Content.ReadAsStringAsync(); return(responseJson); } else if (Equals(response.ReasonPhrase, "Object Not Found")) //need to create database { var contents = new StringContent("", Encoding.UTF8, "application/json"); response = await _client.PutAsync(_client.BaseAddress + _dbName, contents); //creating database using PUT request if (response.IsSuccessStatusCode) //if successful, try POST request again { response = await _client.PostAsync(_client.BaseAddress + _dbName, new StringContent(jsonInString, Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { var responseJson = await response.Content.ReadAsStringAsync(); return(responseJson); } } } string msg = "Failure to POST. Status Code: " + response.StatusCode + ". Reason: " + response.ReasonPhrase; Console.WriteLine(msg); return(JsonConvert.SerializeObject(new { msg = "Failure to POST. Status Code: " + response.StatusCode + ". Reason: " + response.ReasonPhrase })); }