Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.Net MVC 4 C# -- default "CreateBy" column

Posted on 2013-06-10
3
Medium Priority
?
34 Views
Last Modified: 2015-12-08
Does anyone have a better way to do below step #3 and #4 ?
I use these columns all the time and want to make it as easy as possible.
-----------------------------------------------------------------------
1.      add fields to POdetail database table
¿      varChar ¿ CreatedBy / LastModifiedBy
¿      datetime ¿ CreateDate / ModifiedDate
-----------------------------------------------------------------------
2.      add Create, Delete, Details, Edit, Index cshtml pages via Scaffolding as usual
-----------------------------------------------------------------------
3.      edit POdetailController.cs
¿      change below Create method
POdetail myEntity = new POdetail();
myEntity.CreatedBy = User.Identity.Name;
myEntity.CreateDate = DateTime.Now;
myEntity.LastModifiedBy = User.Identity.Name;
myEntity.ModifiedDate = DateTime.Now;
return View(myEntity);
¿      change below Edit method
podetail.ModifiedDate = DateTime.Now;
podetail.LastModifiedBy = User.Identity.Name;
return View(podetail);
-----------------------------------------------------------------------
4.      edit Create.cshtml & Edit.cshtml
¿      change below so it is READONLY to user,  READWRITE to app
@Html.DisplayFor(model=> model.CreatedBy)
@Html.HiddenFor(model=> model.CreatedBy)
0
Comment
Question by:finance_teacher
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
AnuTiji earned 2000 total points
ID: 39236788
Instead of updating the createdby, modified date at the controller end, we can do it in repository end before updating the entities
0
 

Author Comment

by:finance_teacher
ID: 39237400
Do you have example websites/etc of "repository end" updating ?
Are you talking database triggers/etc or Model1.edmx changes ?
0
 

Author Comment

by:finance_teacher
ID: 39292856
Please reply
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Screencast - Getting to Know the Pipeline
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question