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.4k
Save record in database using linq.
Jul 28 2020 11:30 AM
{
"userInjuries": {
"userId": 4,
"userInjuriesList": [
{
"userInjuriesTypeId": 4,
"description": "ABC",
"date": "22/7/1990"
}
]
}
}
How to store this type Format Data in database.I have make a api but i have a problem.Please check me code.
it's me save code.
[Produces(
"application/json"
)]
[Route(
"SavePhysicalInjueris"
)]
[AllowAnonymous]
public
InjuerisResult SavePhysicalInjueris(Root Json)
{
InjuerisResult obj_result =
new
InjuerisResult();
try
{
if
(Json ==
null
)
{
obj_result.Response = 2;
obj_result.ErrorMessage =
" object is null"
;
}
else
{
List<TblInjurie> list_Injurie =
new
List<TblInjurie>();
var JsonData = JsonConvert.SerializeObject((Json));
UserInjuries list = JsonConvert.DeserializeObject<UserInjuries>(JsonData);
foreach
(var res
in
list.UserInjuriesList)------ Here I have face a issue (list.UserInjuriesList
null
)
{
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 = list.UserId;
obj_tblInjurie.IsActive =
true
;
obj_tblInjurie.UpdatedDate = DateTime.UtcNow;
list_Injurie.Add(obj_tblInjurie);
}
_context.TblInjurie.AddRange(list_Injurie);
_context.SaveChanges();
It's me modle code
[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
; }
}
public
class
UserInjuries
{
public
int
? UserId {
get
;
set
; }
public
List<InjerisDetail> UserInjuriesList {
get
;
set
; }
}
public
class
Root
{
public
UserInjuries userInjuries {
get
;
set
; }
}
Please resolve this issue it's important for me.
Reply
Answers (
5
)
Blazor in ASP.NET core
logout using link button in asp.net c#