Ejemplo n.º 1
0
 public async Task <UpdateLoginUserTypesResponse> Post([FromBody] LoginUserTypeAddRequest loginusertype)
 {
     if (_postUserLoginTypeProcessor != null)
     {
         return(await _postUserLoginTypeProcessor.PostNewUserRecord(loginusertype, _cloudantService));
     }
     else
     {
         return(new UpdateLoginUserTypesResponse());
     }
 }
        public async Task <dynamic> Post([FromBody] LoginUserTypeAddRequest employee)
        {
            if (_cloudantService != null)
            {
                return(await _cloudantService.CreateAsync(employee));

                //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" });
            }
        }
Ejemplo n.º 3
0
        public async Task <UpdateLoginUserTypesResponse> PostNewUserRecord(LoginUserTypeAddRequest loginUserTypeAddRequest, 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(loginUserTypeAddRequest, DBNames.loginusertype.ToString());

                // var audit = await cloudantService.CreateAsync(auditData, DBNames.auditdata.ToString());
                return(JsonConvert.DeserializeObject <UpdateLoginUserTypesResponse>(response));
            }
            else
            {
                return(new UpdateLoginUserTypesResponse());
            }
        }
Ejemplo n.º 4
0
        public async Task <dynamic> CreateAsync(LoginUserTypeAddRequest 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 }));
        }