Я пытаюсь сохранить объект, используя HTTP Post Method в моем контроллере API, но он возвращает ошибку, я пытался сделать то же самое в другом контроллере, и это работает. Я надеюсь, что вы можете помочь!
Запрос, который я попробовал:
{
"integrationServiceHost": "10.80.80.10",
"RouterHost": "10.80.80.10",
"Enabled": "false",
"IntegrationServiceRemotePort": "1234",
"RouterSocketPort":"1234",
"RouterRemotePort":"1234",
"IDChannelBehavior":"10",
"IDEPS":"1",
"Description":"Teste Whats",
"IDChannel":"0"
}
ChannelWhatsapp Класс:
public class ChannelWhatsApp : Channel
{
public ChannelWhatsApp();
[Column("WHATSAPP_UserName")]
public string UserName { get; set; }
[Column("WHATSAPP_Password")]
public string Password { get; set; }
[Column("WHATSAPP_DisplayName")]
public string DisplayName { get; set; }
}
URL: http://172.19.22.81:5000/api/channelWhatsapp/saveDto
Класс канала:
public abstract class Channel : NotifyPropertyChanged
{
public Channel();
public virtual ICollection<Interaction> Interaction { get; set; }
public virtual ICollection<Schedule> Schedule { get; set; }
public virtual ICollection<Queue> Queue { get; set; }
public virtual ICollection<Session> Session { get; set; }
public virtual ChannelBehavior ChannelBehavior { get; set; }
public virtual EPS EPS { get; set; }
public DateTime? DtLastChange { get; set; }
[MaxLength(100)]
public string IntegrationServiceHost { get; set; }
[MaxLength(100)]
public string RouterHost { get; set; }
public bool Enabled { get; set; }
public int? IntegrationServiceRemotePort { get; set; }
public int? RouterSocketPort { get; set; }
public int? RouterRemotePort { get; set; }
[ForeignKey("ChannelBehavior")]
public int IDChannelBehavior { get; set; }
[ForeignKey("EPS")]
public int IDEPS { get; set; }
[MaxLength(200)]
public string Description { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public int IDChannel { get; set; }
[NotMapped]
public string IconName { get; set; }
[NotMapped]
public byte? PendingPauseCode { get; set; }
[NotMapped]
public bool IsPausePending { get; set; }
[NotMapped]
public SystemUserOperator Operator { get; set; }
[NotMapped]
public DateTime StateMomment { get; set; }
[NotMapped]
public UserStateType CurrentState { get; set; }
public virtual ICollection<ChannelSkill> ChannelSkills { get; set; }
[NotMapped]
public ChannelTypeType Type { get; set; }
}
Мой контроллер:
[Route("api/ChannelWhatsapp/{Action}")]
[ApiController]
public class ChannelWhatsappController : IrideController<ChannelWhatsApp>
{
public ChannelWhatsappController(IrideContext context) : base(context) { }
[HttpPost("")]
[ActionName("saveDto")]
public IActionResult saveDto([FromBody] ChannelWhatsApp entity)
{
try
{
////Obtem o data
//entity.DtLastChange = IrideUtil.getDate() ;
//_context.Set<ChannelWhatsApp>().Update(entity);
//_context.SaveChanges();
return Ok(entity);
}
catch (Exception ex)
{
return Ok(ex.ToString());
}
}
}
вернулась ошибка:
Исключение: неверный канал IrideCM.Model.Channel..ctor ()
IrideCM.Model.ChannelWhatsApp..ctor () lambda_method (Closure)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject (JsonReader
читатель, JsonObjectContract objectContract, JsonProperty
containerMember, JsonProperty containerProperty, идентификатор строки, вне bool
созданный FromNonDefaultCreator) в JsonSerializerInternalReader.cs
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (JsonReader
читатель, тип objectType, контракт JsonContract, член JsonProperty,
JsonContainerContract containerContract, JsonProperty containerMember,
объект существующего значения) в JsonSerializerInternalReader.cs
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (JsonReader
читатель, введите objectType, bool checkAdditionalContent) в
JsonSerializerInternalReader.cs