public async Task <UpdateCalendarLogRs> DeleteEvent(DeleteCalendarLogRq request) { var result = new UpdateCalendarLogRs(); try { _logger.LogDebug("Getting sensor data from api"); var baseUrl = _configuration.GetSection("PlantApi").GetSection("BaseUrl").Value.ToString(); _logger.LogInformation($"ApiBaseUrl -> {baseUrl}"); var httpRequest = new HttpRequestMessage(HttpMethod.Delete, $"{baseUrl}api/Calendar/{request.id}"); var client = _clientFactory.CreateClient(); var response = await client.SendAsync(httpRequest); if (response.IsSuccessStatusCode) { result = await response.Content.ReadAsAsync <UpdateCalendarLogRs> (); } else { result = null; } } catch (System.Exception ex) { _logger.LogError(ex.Message); throw; } return(result); }
public IActionResult Update([FromBody] UpdateCalendarLogRq request) { var result = new UpdateCalendarLogRs(); if (request == null || string.IsNullOrEmpty(request.Title)) { return(StatusCode(400, "Please fill correctly request.")); } else { _logger.LogInformation($" [Request] ... {JsonConvert.SerializeObject(request)}"); } try { using (MySqlConnection connection = new MySqlConnection(_appSettings.GetDataBaseConnectionString())) { connection.Open(); var query = $"UPDATE CALENDAR_EVENT " + $"SET title = @title " + $", start = @start " + $", end = @end " + $", timestamp = @timestamp " + $"WHERE id = @id"; var command = new MySqlCommand(query, connection); command.Parameters.Add("@id", MySqlDbType.Int32); command.Parameters["@id"].Value = request.Id; command.Parameters.Add("@title", MySqlDbType.String); command.Parameters["@title"].Value = request.Title; command.Parameters.Add("@start", MySqlDbType.DateTime); command.Parameters["@start"].Value = request.Start; command.Parameters.Add("@end", MySqlDbType.DateTime); command.Parameters["@end"].Value = request.End; command.Parameters.Add("@timestamp", MySqlDbType.DateTime); command.Parameters["@timestamp"].Value = DateTime.Now; Int32 id = (int)command.ExecuteNonQuery(); _logger.LogInformation($" [Updated] ... {id}"); } } catch (System.Exception ex) { _logger.LogError($"{ex.Message}"); return(StatusCode(500)); } return(StatusCode(200)); }