protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); Debug.Assert(Request.IsAuthenticated); var user = User.Identity.Name; using (var ctx = new OffwindEntities()) { var dCase = ctx.DCases.FirstOrDefault(c => c.Owner == user && c.Name == StandardCases.WindWave); if (dCase == null) { // Init basic properties dCase = new DCase(); dCase.Id = Guid.NewGuid(); dCase.Name = StandardCases.WindWave; dCase.Owner = user; dCase.Created = DateTime.UtcNow; // Init model var model = CreateProjectModel(); var serializer = new XmlSerializer(typeof(WindWaveInput)); using (var writer = new StringWriter()) { serializer.Serialize(writer, model); dCase.Model = writer.ToString(); writer.Close(); } ctx.DCases.AddObject(dCase); ctx.SaveChanges(); } } base.Initialize(requestContext); }
protected void SetDbModel(WindWaveInput model) { var serializer = new XmlSerializer(typeof(WindWaveInput)); using (var ctx = new OffwindEntities()) using (var writer = new StringWriter()) { var dCase = ctx.DCases.First(c => c.Owner == User.Identity.Name && c.Name == StandardCases.WindWave); serializer.Serialize(writer, model); dCase.Model = writer.ToString(); writer.Close(); ctx.SaveChanges(); } }