110,539
社区成员
发帖
与我相关
我的任务
分享
create table XMLFORM (
ID int identity,
FORMXML xml not null,
constraint PK_XMLFORM primary key (ID)
)
[AcceptVerbs(HttpVerbs.Post),ValidateInput(false)]
public ActionResult New(string xmlContent)
{
xmlContent = Server.UrlDecode(xmlContent);
if (!string.IsNullOrEmpty(xmlContent))
{
//if (!CheckXML(xmlContent, out strError)) //服务器端检测,如果用了ajax检测,就没必要了
//{
// ModelState.AddModelError("_FORM",strError);
// return View();
//}
XMLFormDataContext db = new XMLFormDataContext();
TransactionOptions opt = new TransactionOptions();
opt.IsolationLevel = IsolationLevel.Serializable;
using (TransactionScope tran = new TransactionScope(TransactionScopeOption.RequiresNew, opt))
{
XMLFORM f = new XMLFORM();
try
{
f.FORMXML = XElement.Parse(xmlContent);
db.XMLFORMs.InsertOnSubmit(f);
db.SubmitChanges();
var id = db.XMLFORMs.Max(p => p.ID);
TempData["resultMessage"] = "Success";
TempData["id"] = (int)id;
return RedirectToAction("Result");
}
catch
{
TempData["resultMessage"] = "failure";
ModelState.AddModelError("_FORM", "envalid xml format");
return View();
}
}
}
else
return View();
}
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.3074
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MVCMembership.Models
{
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
using System.ComponentModel;
using System;
[System.Data.Linq.Mapping.DatabaseAttribute(Name="Test")]
public partial class XMLFormDataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
#region Extensibility Method Definitions
partial void OnCreated();
partial void InsertXMLFORM(XMLFORM instance);
partial void UpdateXMLFORM(XMLFORM instance);
partial void DeleteXMLFORM(XMLFORM instance);
#endregion
public XMLFormDataContext() :
base(global::System.Configuration.ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}
public XMLFormDataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
public XMLFormDataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public XMLFormDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public XMLFormDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public System.Data.Linq.Table<XMLFORM> XMLFORMs
{
get
{
return this.GetTable<XMLFORM>();
}
}
}
[Table(Name="dbo.XMLFORM")]
public partial class XMLFORM : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private int _ID;
private System.Xml.Linq.XElement _FORMXML;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnIDChanging(int value);
partial void OnIDChanged();
partial void OnFORMXMLChanging(System.Xml.Linq.XElement value);
partial void OnFORMXMLChanged();
#endregion
public XMLFORM()
{
OnCreated();
}
[Column(Storage="_ID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
public int ID
{
get
{
return this._ID;
}
set
{
if ((this._ID != value))
{
this.OnIDChanging(value);
this.SendPropertyChanging();
this._ID = value;
this.SendPropertyChanged("ID");
this.OnIDChanged();
}
}
}
[Column(Storage="_FORMXML", DbType="Xml NOT NULL", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
public System.Xml.Linq.XElement FORMXML
{
get
{
return this._FORMXML;
}
set
{
if ((this._FORMXML != value))
{
this.OnFORMXMLChanging(value);
this.SendPropertyChanging();
this._FORMXML = value;
this.SendPropertyChanged("FORMXML");
this.OnFORMXMLChanged();
}
}
}
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
#pragma warning restore 1591