public ActionResult <AreaResponse> Area(Guid id) { using (var db = new FigureContext()) { var figure = db.Figures.Find(id); var model = JsonSerializer.Deserialize <Figure>(figure.Data); return(new AreaResponse() { Area = model.Area() }); } }
public ActionResult <IdResponse> Figure([FromBody] Figure figure) { var id = Guid.NewGuid(); using (var db = new FigureContext()) { db.Add(new db.Figure() { Id = id, Data = JsonSerializer.Serialize(figure) }); db.SaveChanges(); } return(new IdResponse() { Id = id }); }
public static void EnsureSeedDataForContext(this FigureContext context) { if (context.Figures.Any()) { return; } // Init seed data. var figures = new List <Figure>() { new Figure() { FigureType = FigureType.Fictional, FirstName = "Hanzo", LastName = "Hasashi", Gender = Gender.Male, Alias = "Scorpion", Description = "Leader of the Shirai Ryu clan, master assassin. Deceased, and later resurrected by Quan Chi." }, new Figure() { FigureType = FigureType.Fictional, FirstName = "Bi", LastName = "Han", Gender = Gender.Male, Alias = "Sub-Zero", UniquelyDisplayedFullName = "Bi-Han", Description = "Leader of the Lin Kuei clan. Childhood friend of Hanzo Hasashi, later on, killed by him." }, new Figure() { FigureType = FigureType.Mythological, FirstName = "Athene", LastName = "Pallas", Gender = Gender.Female, Alias = "Athena", Description = "Godess of wisdom, justice, just war, art and education. Daughter of Zeus and Metis", IsLastNameFirst = true } }; context.AddRange(figures); context.SaveChanges(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, FigureContext dataContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } dataContext.Database.Migrate(); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public FigureRepository(FigureContext context) { _context = 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, FigureContext figureContext) { loggerFactory.AddConsole(); loggerFactory.AddDebug(); loggerFactory.AddNLog(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } figureContext.EnsureSeedDataForContext(); app.UseStatusCodePages(); AutoMapper.Mapper.Initialize(config => { config.CreateMap <Entities.Figure, Models.FigureDto>(); config.CreateMap <Entities.Figure, Models.FigureForUpdateDto>(); config.CreateMap <Models.FigureForCreationDto, Entities.Figure>(); config.CreateMap <Models.FigureForUpdateDto, Entities.Figure>(); }); app.UseMvc(); }
public DummyController(FigureContext ctx) { _ctx = ctx; }