public IActionResult putExpenseReport([FromBody] FarmExpenseDetails jsonString) { try { bool output = false; using (var sqlConnection = new SqlConnection(_appSettings.ConnectionString)) { using (var sqlCommand = new SqlCommand("dbo.usp_put_farmexpensereport", sqlConnection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.Add("@json", SqlDbType.NVarChar, -1).Value = JsonConvert.SerializeObject(jsonString); sqlCommand.Parameters.Add("@output", SqlDbType.Bit); sqlCommand.Parameters["@output"].Direction = ParameterDirection.Output; sqlConnection.Open(); sqlCommand.ExecuteReader(); sqlConnection.Close(); output = (bool)sqlCommand.Parameters["@output"].Value; } } return(Ok(output)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult getExpenseReport(int Id) { try { FarmExpenseDetails data = new FarmExpenseDetails(); using (var sqlConnection = new SqlConnection(_appSettings.ConnectionString)) { using (var sqlCommand = new SqlCommand("dbo.usp_get_farmexpensereport", sqlConnection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.Add("@farm_id", SqlDbType.Int).Value = Id; sqlConnection.Open(); SqlDataReader reader = sqlCommand.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { data.agent_id = Int32.Parse(reader["agent_id"].ToString()); data.farm_id = Int32.Parse(reader["farm_id"].ToString()); data.farm_expense_id = Int32.Parse(reader["farm_expense_id"].ToString()); data.crop_type = reader["CropType"].ToString(); data.land_acers = float.Parse(reader["LandAcers"].ToString()); data.profit_share = float.Parse(reader["ProfitShare"].ToString()); data.start_date = DateTime.Parse(reader["StartDate"].ToString()).ToString("yyyy-MM-dd"); data.end_date = DateTime.Parse(reader["EndDate"].ToString()).ToString("yyyy-MM-dd"); string exp = reader["Expenses"].ToString(); exp = exp == ""?"[]":exp; data.expenses = JArray.Parse(exp); } return(Ok(new { result = data })); } else { sqlConnection.Close(); return(Ok(new { result = "" })); } } } } catch (Exception ex) { return(BadRequest(ex.Message)); } }