TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
611
127.8k
Post data in .net core
Jul 24 2020 8:36 AM
I want to insert data in database this format-
{
"userInjuries": {
"UserId": 4,
"UserInjuriesList": [
{
"UserInjuriesTypeId": 4,
"Description": "Over Wegiht",
"Date": "22/7/2020"
},
{
"UserInjuriesTypeId": 4,
"Description": "Over Wegiht",
"Date": "22/7/2020"
}
]
}
}
public
InjuerisResult SavePhysicalInjueris([FromBody] ObjectRoot obj_parameter)
{
InjuerisResult obj_result =
new
InjuerisResult();
try
{
if
(obj_parameter ==
null
)
{
obj_result.Response = 2;
obj_result.ErrorMessage =
" object is null"
;
}
else
{
List<TblInjurie> list_Injurie =
new
List<TblInjurie>();
string
json = Request.Form[
"UserInjuries"
]; --- Here error
throw
(incorrect content-type: application/json-patch+json)
UserInjuries list = JsonConvert.DeserializeObject<UserInjuries>(json);
foreach
(var res
in
list.UserInjuriesList)
{
var obj_tblInjurie =
new
TblInjurie();
obj_tblInjurie.Date = DateTime.ParseExact(res.Date,
"d/M/yyyy"
, CultureInfo.InvariantCulture);
obj_tblInjurie.Description = res.Description;
obj_tblInjurie.UserInjuriesTypeId = res.UserInjuriesTypeId;
obj_tblInjurie.UserId = res.UserId;
obj_tblInjurie.IsActive =
true
;
obj_tblInjurie.UpdatedDate = DateTime.UtcNow;
list_Injurie.Add(obj_tblInjurie);
}
_context.TblInjurie.AddRange(list_Injurie);
_context.SaveChanges();
}
obj_result.Response = 1;
obj_result.ErrorMessage =
"No Error Found"
;
}
catch
(Exception ex)
{
obj_result.Response = 0;
obj_result.ErrorMessage =
"Internal Server Error"
;
}
return
obj_result;
}
It's me model code.
public
class
ObjectRoot
{
public
UserInjuries UserInjuries {
get
;
set
; }
}
public
class
UserInjuries
{
//public string InjuriesDetails { get; set; }
public
List<InjerisDetail> UserInjuriesList {
get
;
set
; }
}
[Table(
"TblInjurie"
)]
public
class
InjerisDetail
{
public
int
? UserId {
get
;
set
; }
public
int
UserInjuriesTypeId {
get
;
set
; }
public
string
Description {
get
;
set
; }
public
bool
? IsActive {
get
;
set
; }
[Column(TypeName =
"date"
)]
public
string
Date {
get
;
set
; }
}
Please check and resolve issue.
Reply
Answers (
3
)
Windows Media services
How to handle Http 403.14 error for MVC application hosting .