예제 #1
0
 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();
     }
 }
예제 #2
0
        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);
            }
        }
예제 #3
0
 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);
     }
 }
예제 #4
0
 public TigerSeeder(TigerContext ctx, IWebHostEnvironment hosting, UserManager <StoreUser> userManager)
 {
     _ctx         = ctx;
     _hosting     = hosting;
     _userManager = userManager;
 }