Solved

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

Posted on 2013-06-10
3
29 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 500 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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