Isaac Johnson
asked on
List Processing - Losing list data between controller and model
I am creating a webAPI which returns 2 columns to a list as 1 row When I test with powermon or
via html I only return [{}] . I know I have captured the data because I see the row in visual studio.
For some reason when I return to the controller the data that is in the model packet
for return from controller the data is missing returning only see [{}]
Can anyone offer a solution or suggestions.
I'm under the gun.
Isaac
via html I only return [{}] . I know I have captured the data because I see the row in visual studio.
For some reason when I return to the controller the data that is in the model packet
for return from controller the data is missing returning only see [{}]
Can anyone offer a solution or suggestions.
I'm under the gun.
Isaac
// Controller
using PicOfDay;
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using PicOfDay.Models;
using Newtonsoft.Json;
using System.Data;
namespace PicOfDay.Controllers
{
public class PicOfDayController : ApiController
{
[Route("api/PicOfDay/pic_of_day/{id}")]
[HttpGet]
public IHttpActionResult pic_of_day(string id)
{
try
{
List<PictureOfDay> PicDateCaption = new List<PictureOfDay>();
var picofday = new PictureOfDay();
picofday.pic_of_day(PicDateCaption, id);
return Ok(PicDateCaption);
}
catch (Exception ex)
{
return InternalServerError(ex);
}
}
}
}
//=========================================
//Model
///=========================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Data.SqlClient;
using System.Collections;
using UtilityServices;
using DataLayerServices;
using InsightDataServices;
using System.Data;
namespace PicOfDay.Models
{
public class PictureOfDay
{
//string showCounts = "1";
//int TotalCount;
string Pic_Date;
string Pic_Caption;
public List<PictureOfDay> pic_of_day(List<PictureOfDay> PicDateCaption, string Date_In)
{
using (var con = Database.GetConnection())
{
// Find Pic Of Day
using (SqlCommand command = new SqlCommand("insight_sel_pic_day", con))
{
command.CommandType = System.Data.CommandType.StoredProcedure;
con.Open();
command.Parameters.Add(new SqlParameter("@INpic_date", System.Data.SqlDbType.NChar)).Value = Date_In;
using (SqlDataReader rdr = command.ExecuteReader())
// Locate Picture
if (rdr.HasRows)
while (rdr.Read())
{
PictureOfDay picData = new PictureOfDay();
picData.Pic_Date = Date_In.ToString();
picData.Pic_Caption = rdr["caption"].ToString();
PicDateCaption.Add(picData);
}
con.Close();
return PicDateCaption;
}
}
}
}
}
//===================================================
ASKER
No. The data is there apparently as seen in attachment I have included.
PicDateCaption.png
PicDateCaption.png
Replace :
and make sure your properties in PictureOfDay are public properties.
return Ok(PicDateCaption);
with'return PicDateCaption;
and make sure your properties in PictureOfDay are public properties.
ASKER
The return from controller must have status ie return Ok(PicDateCaption);
In thinking maybe the status is not Ok, therefore not returning value.
Can I change Ok to !Ok. Want see if that is the problem
In thinking maybe the status is not Ok, therefore not returning value.
Can I change Ok to !Ok. Want see if that is the problem
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks,
You saved the day!
Isaac
You saved the day!
Isaac
Did you mean to add picofday to PicDateCaption ?
If that is the case then add the line below : ( at line 33 before return Ok(PicDateCaption))
Open in new window