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);
        }
Beispiel #2
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");


            using (var ctx = new OffwindEntities())
            {
                var ct = ContentType.Page.S();
                foreach (var dc in ctx.DContents.Where(c => c.TypeId == ct))
                {
                    if (dc.Route.Trim().Length <= 0) continue;
                    routes.MapRoute(
                        dc.Id.ToString(),
                        dc.Route,
                        new { controller = "Content", action = "ShowById", id = dc.Id },
                        new[] { "Offwind.WebApp.Controllers" }
                    );
                }
            }

            routes.MapRoute(
                "Default",
                "{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                new [] {"Offwind.WebApp.Controllers"}
            );
        }
Beispiel #3
0
 public static BlockModel GetBlock(string name,ContentType type)
 {
     using (var ctx = new OffwindEntities())
     {
         var ctBlock = type.ToString();
         var content = ctx.DContents.FirstOrDefault(c => c.TypeId == ctBlock && c.Name == name);
         var block = new BlockModel();
         if (content != null)
         {
             block.Name = content.Name;
             block.Title = content.Title;
             block.Content = content.Content;
             block.Image = content.Announce;
         }
         return block;
     }
 }
 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();
     }
 }
 protected WindWaveInput GetDbModel()
 {
     using (var ctx = new OffwindEntities())
     {
         var dCase = ctx.DCases.First(c => c.Owner == User.Identity.Name && c.Name == StandardCases.WindWave);
         var serializer = new XmlSerializer(typeof(WindWaveInput));
         using (var reader = new StringReader(dCase.Model))
         {
             return (WindWaveInput)serializer.Deserialize(reader);
         }
     }
 }