public void CreateTiger(TigerModel model) { using (var context = new TigerContext()) { var entity = new Tiger { Id = Guid.NewGuid(), Color = model.Color, Weight = model.Weight }; context.Tigers.Add(entity); context.SaveChanges(); } }
public List <TigerModel> GetAllTigers() { using (var context = new TigerContext()) { var entities = context.Tigers.ToList(); var models = context.Tigers.Select(entity => new TigerModel { Id = entity.Id, Color = entity.Color, Weight = entity.Weight }).ToList(); return(models); } }
public TigerModel GetTiger(Guid id) { using (var context = new TigerContext()) { var entity = context.Tigers.Single(x => x.Id == id); //Vad händer om vi inte hittar någon tiger? var nests = entity.Nests.ToList(); var model = new TigerModel { Id = entity.Id, Color = entity.Color, Weight = entity.Weight, Nests = nests.Select(x => new NestModel { Id = x.Id, Type = x.Type, FirstChoice = x.FirstChoice, Value = x.Id, Text = x.Type.ToString() }).ToList() }; return(model); } }
public TigerSeeder(TigerContext ctx, IWebHostEnvironment hosting, UserManager <StoreUser> userManager) { _ctx = ctx; _hosting = hosting; _userManager = userManager; }