public ActionResult SaveProduct(Product productData)
{
Product productToSave = null;
string msg = string.Empty;
bool success = true;
// Look whether the user exists. Then get that user, else create a new one
if (Product.Exists(new Product.ExistCriteria(productData.ProductId)))
{
productToSave = Product.GetProduct(productData.ProductId);
// check for concurrency errors
if (productToSave.VersionTimeStamp.ToString() != productData.VersionTimeStamp.ToString())
{
productToSave = null;
success = false;
msg = "Concurrency Error";
}
}
else productToSave = Product.NewProduct();
// Map the properties of userdata and userTosave, except the Roles collection
// Roles collection is empty in userdata, needs a seperate method call
if (productToSave != null)
{
Csla.Data.DataMapper.Map(productData, productToSave, "Substances", "Routes", "DefaultName", "KAE");
}
try
{
productToSave = Informedica.GenForm.Library.DomainModel.Import.ImportWizard.PrepareProductSave(productToSave);
productToSave = productToSave.Save();
}
catch (Exception e)
{
msg = e.Message;
success = false;
}
// Return the result
return this.Direct(
new
{
success = success,
msg = msg,
errors = productToSave == null ? string.Empty : msg,
data = productToSave == null ? null : productToSave
});
}