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
129.3k
Record Update In c#
Sep 10 2020 4:54 AM
I have faced a problem. I want to save and update record .Record Save successfully but update case i have face problem. It's my model classes.
public
class
Root
{
public
UserInjuries UserInjuries {
get
;
set
; }
}
public
class
UserInjuries
{
public
int
? UserId {
get
;
set
; }
public
List<InjerisDetail> UserInjuriesList {
get
;
set
; }
}
[Table(
"TblInjurie"
)]
public
class
InjerisDetail
{
public
string
UserInjuriesTypeId {
get
;
set
; }
public
string
Description {
get
;
set
; }
public
bool
? IsActive {
get
;
set
; }
[Column(TypeName =
"date"
)]
public
string
Date {
get
;
set
; }
}
It's me save and update code .
Root Json)
{
InjuerisResult obj_result =
new
InjuerisResult();
try
{
var injurie = _context.TblInjurie.Where(x => x.UserId == Json.UserInjuries.UserId && x.UserInjuriesTypeId==Json.UserInjuries.UserInjuriesList.).FirstOrDefault();Here Not I have showing UserInjuriesTypeId .Please provide solution please it's imp
for
me
if
(injurie !=
null
)
{
List<TblInjurie> list_Injurie =
new
List<TblInjurie>();
foreach
(var res
in
Json.UserInjuries.UserInjuriesList)
{
//var obj_tblInjurie = new TblInjurie();
injurie.Date = DateTime.ParseExact(res.Date,
"d/M/yyyy"
, CultureInfo.InvariantCulture);
injurie.Description = res.Description;
injurie.UserInjuriesTypeId = Convert.ToInt32(res.UserInjuriesTypeId);
injurie.UserId = Json.UserInjuries.UserId;
injurie.IsActive =
true
;
injurie.UserInjurieStatus =
true
;
injurie.UpdatedDate = DateTime.UtcNow;
list_Injurie.Add(injurie);
_context.SaveChanges();
}
//_context.TblInjurie.AddRange(list_Injurie);
//_context.SaveChanges();
}
else
{
List<TblInjurie> list_Injurie =
new
List<TblInjurie>();
foreach
(var res
in
Json.UserInjuries.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 =Convert.ToInt32 (res.UserInjuriesTypeId);
obj_tblInjurie.UserId = Json.UserInjuries.UserId;
obj_tblInjurie.IsActive =
true
;
obj_tblInjurie.UserInjurieStatus =
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;
}
Reply
Answers (
1
)
binaryreader.ReadInt32() reads too big or -ve value
RPC Server, RPC Client