Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I have my custom code working and successfully submitting the form but it takes about 7 seconds minimum to complete which is way to long.
Any ideas why it is taking that long to complete?
The code inside my controller is as follows:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult HandleHomeEnquiryForm(HomeEnquiryFormViewModel model)
{
if (!ModelState.IsValid)
return PartialView("HomeEnquiryForm", model);
}
Hashtable hash = (Hashtable)Session["CentreEmailsHash"];
string emailTo = hash[int.Parse(model.Centre)].ToString();
TempData["CentreEmail"] = emailTo;
//var currentNode = Umbraco.TypedContent(UmbracoContext.PageId);
using (var recordStorage = new RecordStorage())
using (var formStorage = new FormStorage())
var form = formStorage.GetForm(new Guid("4cfe3068-75e4-4c9d-8ce7-d1c084642a85"));
using (var recordService = new RecordService(form))
recordService.Open();
var record = recordService.Record;
record.IP = Request.UserHostAddress;
record.UmbracoPageId = 1051; // Need to get current page ID
recordStorage.InsertRecord(record, form);
foreach (var f in recordService.Form.AllFields)
//emailTo
if (f.Caption == "EmailTo")
var key = Guid.NewGuid();
var recordField = new RecordField()
Field = f,
Key = key,
Record = record.Id,
Values = new List<object>() { emailTo }
};
var recordFieldStorage = new RecordFieldStorage();
recordFieldStorage.InsertRecordField(recordField);
record.RecordFields.Add(key, recordField);
//Name
if (f.Caption == "Name")
Values = new List<object>() { model.Name }
//Phone
if (f.Caption == "Phone")
Values = new List<object>() { model.Phone }
//Email
if (f.Caption == "Email")
Values = new List<object>() { model.Email }
//Message
if (f.Caption == "Message")
Values = new List<object>() { model.Message }
//User Entry Page
if (f.Caption == "User Entry Page")
Values = new List<object>() { model.UserEntryPage }
//PageSubmittedOn
if (f.Caption == "PageSubmittedOn")
Values = new List<object>() { model.PageSubmittedOn }
//Site ID
if (f.Caption == "Site ID")
Values = new List<object>() { model.Centre }
//Site Name
if (f.Caption == "Site Name")
Values = new List<object>() { "Site Name - Need to get from DDL" }
//Via Mobile
if (f.Caption == "Via Mobile")
Values = new List<object>() { model.IsMobile }
//I am a Human
if (f.Caption == "I am a Human")
Values = new List<object>() { model.IAmAHuman }
recordService.Submit();
recordService.SaveFormToRecord();
TempData["status"] = "Success";
Comment author was deleted
That's indeed way to long, is it also that long when you use the default controller?
Its not the quickest when using custom view (just custom markup) but nowhere near that slow.
Theres various reasons why need to use own controller as need to get values for elements that are system based rathe than user entry.
Yup mind putting your code in a gist (https://gist.github.com/) so it's easier to copy, then I'll give it a try
Haven't got a Gisthub account, can email it to you though?
Sure you can mail to tg at umbraco dot com, thanks
Turns out the delay was caused by some workflows attached to the form, it is sending out emails but the smtp server failed to respond... nothing wrong with the custom controller that works fine and fast.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Creating Records / Entries From Custom Form / Controller
Hi,
I have my custom code working and successfully submitting the form but it takes about 7 seconds minimum to complete which is way to long.
Any ideas why it is taking that long to complete?
The code inside my controller is as follows:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult HandleHomeEnquiryForm(HomeEnquiryFormViewModel model)
{
if (!ModelState.IsValid)
{
return PartialView("HomeEnquiryForm", model);
}
Hashtable hash = (Hashtable)Session["CentreEmailsHash"];
string emailTo = hash[int.Parse(model.Centre)].ToString();
TempData["CentreEmail"] = emailTo;
//var currentNode = Umbraco.TypedContent(UmbracoContext.PageId);
using (var recordStorage = new RecordStorage())
using (var formStorage = new FormStorage())
{
var form = formStorage.GetForm(new Guid("4cfe3068-75e4-4c9d-8ce7-d1c084642a85"));
using (var recordService = new RecordService(form))
{
recordService.Open();
var record = recordService.Record;
record.IP = Request.UserHostAddress;
record.UmbracoPageId = 1051; // Need to get current page ID
recordStorage.InsertRecord(record, form);
foreach (var f in recordService.Form.AllFields)
{
//emailTo
if (f.Caption == "EmailTo")
{
var key = Guid.NewGuid();
var recordField = new RecordField()
{
Field = f,
Key = key,
Record = record.Id,
Values = new List<object>() { emailTo }
};
var recordFieldStorage = new RecordFieldStorage();
recordFieldStorage.InsertRecordField(recordField);
record.RecordFields.Add(key, recordField);
}
//Name
if (f.Caption == "Name")
{
var key = Guid.NewGuid();
var recordField = new RecordField()
{
Field = f,
Key = key,
Record = record.Id,
Values = new List<object>() { model.Name }
};
var recordFieldStorage = new RecordFieldStorage();
recordFieldStorage.InsertRecordField(recordField);
record.RecordFields.Add(key, recordField);
}
//Phone
if (f.Caption == "Phone")
{
var key = Guid.NewGuid();
var recordField = new RecordField()
{
Field = f,
Key = key,
Record = record.Id,
Values = new List<object>() { model.Phone }
};
var recordFieldStorage = new RecordFieldStorage();
recordFieldStorage.InsertRecordField(recordField);
record.RecordFields.Add(key, recordField);
}
//Email
if (f.Caption == "Email")
{
var key = Guid.NewGuid();
var recordField = new RecordField()
{
Field = f,
Key = key,
Record = record.Id,
Values = new List<object>() { model.Email }
};
var recordFieldStorage = new RecordFieldStorage();
recordFieldStorage.InsertRecordField(recordField);
record.RecordFields.Add(key, recordField);
}
//Message
if (f.Caption == "Message")
{
var key = Guid.NewGuid();
var recordField = new RecordField()
{
Field = f,
Key = key,
Record = record.Id,
Values = new List<object>() { model.Message }
};
var recordFieldStorage = new RecordFieldStorage();
recordFieldStorage.InsertRecordField(recordField);
record.RecordFields.Add(key, recordField);
}
//User Entry Page
if (f.Caption == "User Entry Page")
{
var key = Guid.NewGuid();
var recordField = new RecordField()
{
Field = f,
Key = key,
Record = record.Id,
Values = new List<object>() { model.UserEntryPage }
};
var recordFieldStorage = new RecordFieldStorage();
recordFieldStorage.InsertRecordField(recordField);
record.RecordFields.Add(key, recordField);
}
//PageSubmittedOn
if (f.Caption == "PageSubmittedOn")
{
var key = Guid.NewGuid();
var recordField = new RecordField()
{
Field = f,
Key = key,
Record = record.Id,
Values = new List<object>() { model.PageSubmittedOn }
};
var recordFieldStorage = new RecordFieldStorage();
recordFieldStorage.InsertRecordField(recordField);
record.RecordFields.Add(key, recordField);
}
//Site ID
if (f.Caption == "Site ID")
{
var key = Guid.NewGuid();
var recordField = new RecordField()
{
Field = f,
Key = key,
Record = record.Id,
Values = new List<object>() { model.Centre }
};
var recordFieldStorage = new RecordFieldStorage();
recordFieldStorage.InsertRecordField(recordField);
record.RecordFields.Add(key, recordField);
}
//Site Name
if (f.Caption == "Site Name")
{
var key = Guid.NewGuid();
var recordField = new RecordField()
{
Field = f,
Key = key,
Record = record.Id,
Values = new List<object>() { "Site Name - Need to get from DDL" }
};
var recordFieldStorage = new RecordFieldStorage();
recordFieldStorage.InsertRecordField(recordField);
record.RecordFields.Add(key, recordField);
}
//Via Mobile
if (f.Caption == "Via Mobile")
{
var key = Guid.NewGuid();
var recordField = new RecordField()
{
Field = f,
Key = key,
Record = record.Id,
Values = new List<object>() { model.IsMobile }
};
var recordFieldStorage = new RecordFieldStorage();
recordFieldStorage.InsertRecordField(recordField);
record.RecordFields.Add(key, recordField);
}
//I am a Human
if (f.Caption == "I am a Human")
{
var key = Guid.NewGuid();
var recordField = new RecordField()
{
Field = f,
Key = key,
Record = record.Id,
Values = new List<object>() { model.IAmAHuman }
};
var recordFieldStorage = new RecordFieldStorage();
recordFieldStorage.InsertRecordField(recordField);
record.RecordFields.Add(key, recordField);
}
}
recordService.Submit();
recordService.SaveFormToRecord();
}
}
TempData["status"] = "Success";
return PartialView("HomeEnquiryForm", model);
}
Comment author was deleted
That's indeed way to long, is it also that long when you use the default controller?
Its not the quickest when using custom view (just custom markup) but nowhere near that slow.
Theres various reasons why need to use own controller as need to get values for elements that are system based rathe than user entry.
Comment author was deleted
Yup mind putting your code in a gist (https://gist.github.com/) so it's easier to copy, then I'll give it a try
Haven't got a Gisthub account, can email it to you though?
Comment author was deleted
Sure you can mail to tg at umbraco dot com, thanks
Comment author was deleted
Turns out the delay was caused by some workflows attached to the form, it is sending out emails but the smtp server failed to respond... nothing wrong with the custom controller that works fine and fast.
is working on a reply...