Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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 …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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