Why Join
Become a member
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
C# Corner Home
Technologies
MonthlyLeaders
ASK A QUESTION
Forumguidelines
Brunno Obristo
2k
29
1.4k
Get CreateDate and UpdateDate in mvc consuming a webapi
Jul 3 2019 12:16 PM
(Controller)
[ResponseType(
typeof
(
void
))]
public
IHttpActionResult PutVENDEDOR(
int
id, VENDEDOR vENDEDOR)
{
if
(!ModelState.IsValid)
{
return
BadRequest(ModelState);
}
if
(id != vENDEDOR.ID_VENDEDOR)
{
return
BadRequest();
}
db.Entry(vENDEDOR).State = EntityState.Modified;
try
{
//vENDEDOR.DT_ATUALIZA = DateTime.Now.ToString();
db.SaveChanges();
}
catch
(DbUpdateConcurrencyException)
{
if
(!VENDEDORExists(id))
{
return
NotFound();
}
else
{
throw
;
}
}
return
StatusCode(HttpStatusCode.NoContent);
}
// POST: api/Vendedor
[ResponseType(
typeof
(VENDEDOR))]
public
IHttpActionResult PostVENDEDOR(VENDEDOR vENDEDOR)
{
if
(!ModelState.IsValid)
{
return
BadRequest(ModelState);
}
//vENDEDOR.DT_INSERCAO = DateTime.Now.ToString();
db.VENDEDOR.Add(vENDEDOR);
try
{
db.SaveChanges();
}
catch
(DbUpdateException)
{
if
(VENDEDORExists(vENDEDOR.ID_VENDEDOR))
{
return
Conflict();
}
else
{
throw
;
}
}
return
CreatedAtRoute(
"DefaultApi"
,
new
{ id = vENDEDOR.ID_VENDEDOR }, vENDEDOR);
}
(Class)
[Required]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString =
"{0:dd/MM/yyyy HH:mm}"
, ApplyFormatInEditMode =
true
)]
public
DateTime DT_INSERCAO {
get
;
set
; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString =
"{0:dd/MM/yyyy HH:mm}"
, ApplyFormatInEditMode =
true
)]
public
DateTime DT_ATUALIZA {
get
;
set
; }
The problem is, when i update a register, the insert date becomes null
Reply
Answers (
1
)
Batch file is not running properly
GPA calculate program in c++