Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-06-10
3
Medium Priority
?
33 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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 article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

722 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