Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

896 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now