Editor add data in controller to insert to database
Editor add data in controller to insert to database
dpanscik
Posts: 202Questions: 47Answers: 0
In my MVC controller, I need to add two fields "userName" and "dateModified" before a record insert.
Here is the stock controller
public IHttpActionResult DataTransport()
{
var settings = Properties.Settings.Default;
var request = HttpContext.Current.Request;
using (var db = new Database(settings.DbType, settings.DbConnection))
{
var response = new Editor(db, "Flex_OnCall_3Model", "TableID")
.Model<Flex_OnCall_3Model>()
.Field(new Field("dayOC")
.Validator(Validation.DateFormat(Format.DATE_ISO_2822))
.GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_2822))
.SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_2822))
)
.Debug(true)
.Process(request)
.Data();
return Json(response);
}
}
Ive attempted this, but this is not the correct syntax
public IHttpActionResult DataTransport()
{
var settings = Properties.Settings.Default;
var request = HttpContext.Current.Request;
using (var db = new Database(settings.DbType, settings.DbConnection))
{
var response = new Editor(db, "Flex_OnCall_3Model", "TableID")
.Model<Flex_OnCall_3Model>()
.Field(new Field("dayOC")
.Validator(Validation.DateFormat(Format.DATE_ISO_2822))
.GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_2822))
.SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_2822))
)
.Field("userName").SetValue("TestUsername")
.Field("dateMofified").SetValue.(DateTime.Now)
.Debug(true)
.Process(request)
.Data();
return Json(response);
}
}
Answers
Here is the solution. Grab the form key value pairs and add the necessary data.
update....
you need to remove the action string, add in your additional data, then put the action string at the end of the array
update 2...
edit needs its own treatment
Thanks for posting back with your solution!
Allan