//Le damos un contexto en el constructor public RespuestasInfoRepository(AsignacionInfoContext context) { _context = context; }
//Le damos un contexto en el constructor public AsignacionInfoRepository(AsignacionInfoContext context) { _context = context; }
public static void EnsureSeedDataForContext(this AsignacionInfoContext context) { }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, AsignacionInfoContext asignacionInfoContext) { //Registra eventos en la consola loggerFactory.AddConsole(); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(); } //Creamos la estructura de la base de datos con sus datos asignacionInfoContext.EnsureSeedDataForContext(); //La aplicación utiliza los codigos para redirigirnos a diferentes vistas app.UseStatusCodePages(); //Realizamos un mapeo de nuestros Dto's y entidades AutoMapper.Mapper.Initialize(cfg => { cfg.CreateMap <Models.AsignacionSinPreguntasDto, Entities.AsignacionEntity>(); cfg.CreateMap <Models.EvaluacionCreateUpdateDto, Entities.EvaluacionEntity>(); cfg.CreateMap <Models.EvaluacionesWithoutRespuestasDto, Entities.EvaluacionEntity>(); cfg.CreateMap <Models.EvaluacionDto, Entities.EvaluacionEntity>(); cfg.CreateMap <Models.AsignacionDto, Entities.AsignacionEntity>(); cfg.CreateMap <Models.PreguntaDto, Entities.PreguntaEntity>(); cfg.CreateMap <Models.PreguntaWithOneRespuestasDto, Entities.PreguntaEntity>(); cfg.CreateMap <Models.PreguntaCreateDto, Entities.PreguntaEntity>(); cfg.CreateMap <Models.PreguntaUpdateDto, Entities.PreguntaEntity>(); cfg.CreateMap <Models.UsersDto, Entities.UserEntity>(); cfg.CreateMap <Models.UsersSinProyectosDto, Entities.UserEntity>(); cfg.CreateMap <Models.ProyectoDto, Entities.ProyectoEntity>(); cfg.CreateMap <Models.RoleDto, Entities.RoleEntity>(); cfg.CreateMap <Models.User_RoleDto, Entities.User_RoleEntity>(); cfg.CreateMap <Models.SectionWithoutAreaDto, Entities.SectionEntity>(); cfg.CreateMap <Models.SectionDto, Entities.SectionEntity>(); cfg.CreateMap <Models.RespuestaDto, Entities.RespuestaEntity>(); }); //Incluimos todos los cors app.UseCors(builder => builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); //Utiliza el modelo MVC //app.UseMvc(); app.Use(async(context, next) => { await next(); if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value) && !context.Request.Path.Value.StartsWith("/api/")) { context.Request.Path = "/index.html"; await next(); } }); app.UseMvcWithDefaultRoute(); app.UseDefaultFiles(); app.UseStaticFiles(); //app.Run((context) => //{ // throw new Exception("Example exception"); //}); // app.Run(async (context) => // { // await context.Response.WriteAsync("Hello World!"); // }); }
//Le damos un contexto en el constructor public UsersInfoRespository(AsignacionInfoContext context) { _context = context; }
public static void EnsureSeedDataForContext(this AsignacionInfoContext context) { if (context.Sections.Any()) { return; } var Sections = new List <SectionEntity>() { new SectionEntity() { Id = 1, Nombre = "CEREMONIAS" }, new SectionEntity() { Id = 2, Nombre = "ROLES" }, new SectionEntity() { Id = 3, Nombre = "ARTEFACTOS" } }; //var Asignaciones = new List<AsignacionEntity>(){ }; /* var Asignaciones = new List<AsignacionEntity>() * { * new AsignacionEntity() * { * Id = 1, * Nombre = "Asignacion Verano", * PreguntasDeAsignacion = new List<PreguntaEntity>() * { * new PreguntaEntity() * { * Id = 1, * Pregunta = "¿Tienes mas calor que en la comunión de charmander?" * }, * new PreguntaEntity() * { * Id = 2, * Pregunta = "¿Vamos a ser contrataos del tiron?" * } * } * }, * new AsignacionEntity() * { * Id = 2, * Nombre = "Asignacion Primavera" * }, * new AsignacionEntity() * { * Id = 3, * Nombre = "Asignacion Otoño" * }, * new AsignacionEntity() * { * Id = 4, * Nombre = "Asignacion Invierno" * } * };*/ var Users = new List <UserEntity>() { new UserEntity() { Nombre = "Admin", Password = "******", ProyectosDeUsuario = new List <ProyectoEntity>() { new ProyectoEntity() { Id = 1, Nombre = "Proyecto Feria Huida" }, new ProyectoEntity() { Id = 2, Nombre = "Proyecto No Se Que Inventarme" } } }, new UserEntity() { Nombre = "User", Password = "******", ProyectosDeUsuario = new List <ProyectoEntity>() { new ProyectoEntity() { Id = 3, Nombre = "Proyecto Increible" }, new ProyectoEntity() { Id = 4, Nombre = "Proyecto Desbugeo Conciso" } } } }; var Roles = new List <RoleEntity>() { new RoleEntity() { Id = 1, Role = "Usuario" }, new RoleEntity() { Id = 2, Role = "Administrador", } }; var User_Roles = new List <User_RoleEntity>() { new User_RoleEntity() { RoleId = 1, UserNombre = "User" }, new User_RoleEntity() { RoleId = 1, UserNombre = "Admin" }, new User_RoleEntity() { RoleId = 2, UserNombre = "Admin" }, }; context.Sections.AddRange(Sections); // context.Asignaciones.AddRange(Asignaciones); context.Users.AddRange(Users); context.Roles.AddRange(Roles); context.User_Roles.AddRange(User_Roles); context.SaveChanges(); }
public static void EnsureSeedDataForContext(this AsignacionInfoContext context) { /* if (context.Preguntas.Any() && context.Proyectos.Any()) * { * * var Respuestas = new List<RespuestaEntity> * { * new RespuestaEntity() * { * Id = 1, * Estado = false, * PreguntaId = 1, * ProyectoId = 1 * }, * new RespuestaEntity() * { * Id = 2, * Estado = true, * PreguntaId = 2, * ProyectoId = 1 * }, * new RespuestaEntity() * { * Id = 3, * Estado = false, * PreguntaId = 3, * ProyectoId = 1 * }, * new RespuestaEntity() * { * Id = 4, * Estado = true, * PreguntaId = 4, * ProyectoId = 1 * }, * new RespuestaEntity() * { * Id = 5, * Estado = true, * PreguntaId = 5, * ProyectoId = 1 * } * }; * context.Respuestas.AddRange(Respuestas); * context.SaveChanges(); * }*/ if (context.Sections.Any()) { return; } var Sections = new List <SectionEntity>() { new SectionEntity() { Id = 1, Nombre = "CEREMONIAS" }, new SectionEntity() { Id = 2, Nombre = "ROLES" }, new SectionEntity() { Id = 3, Nombre = "ARTEFACTOS" } }; //var Asignaciones = new List<AsignacionEntity>(){ }; /* var Asignaciones = new List<AsignacionEntity>() * { * new AsignacionEntity() * { * Id = 1, * Nombre = "Asignacion Verano", * PreguntasDeAsignacion = new List<PreguntaEntity>() * { * new PreguntaEntity() * { * Id = 1, * Pregunta = "¿Tienes mas calor que en la comunión de charmander?" * }, * new PreguntaEntity() * { * Id = 2, * Pregunta = "¿Vamos a ser contrataos del tiron?" * } * } * }, * new AsignacionEntity() * { * Id = 2, * Nombre = "Asignacion Primavera" * }, * new AsignacionEntity() * { * Id = 3, * Nombre = "Asignacion Otoño" * }, * new AsignacionEntity() * { * Id = 4, * Nombre = "Asignacion Invierno" * } * };*/ var Users = new List <UserEntity>() { new UserEntity() { Nombre = "Admin", Password = "******", ProyectosDeUsuario = new List <ProyectoEntity>() { new ProyectoEntity() { Id = 1, Nombre = "BSA", Fecha = DateTime.Now.Date, /*Evaluaciones = new List<EvaluacionEntity>() * { * new EvaluacionEntity() * { * ProyectoId = 1, * Fecha = DateTime.Now, * Estado = false * }, * new EvaluacionEntity() * { * ProyectoId = 1, * Fecha = DateTime.Now, * Estado = true * }, * }*/ }, new ProyectoEntity() { Id = 2, Nombre = "TESCO", Fecha = DateTime.Now.Date } } }, new UserEntity() { Nombre = "User", Password = "******", ProyectosDeUsuario = new List <ProyectoEntity>() { new ProyectoEntity() { Id = 3, Nombre = "BestDay", Fecha = DateTime.Now.Date }, new ProyectoEntity() { Id = 4, Nombre = "TVE", Fecha = DateTime.Now.Date } } } }; var Roles = new List <RoleEntity>() { new RoleEntity() { Id = 1, Role = "Usuario" }, new RoleEntity() { Id = 2, Role = "Administrador", } }; var User_Roles = new List <User_RoleEntity>() { new User_RoleEntity() { RoleId = 1, UserNombre = "User" }, new User_RoleEntity() { RoleId = 1, UserNombre = "Admin" }, new User_RoleEntity() { RoleId = 2, UserNombre = "Admin" }, }; context.Sections.AddRange(Sections); // context.Asignaciones.AddRange(Asignaciones); context.Users.AddRange(Users); context.Roles.AddRange(Roles); context.User_Roles.AddRange(User_Roles); context.SaveChanges(); }