예제 #1
0
        private async void AddPerson_OnClicked(object sender, EventArgs e)
        {
            var newPersonName = PersonNameEntry.Text;

            if (string.IsNullOrWhiteSpace(newPersonName))
            {
                SetInfoLabel("Name must not be empty.");
                return;
            }
            using (var db = new PetsDbContext())
            {
                var existingPerson = db.People.FirstOrDefault(x => x.Name == newPersonName);
                if (existingPerson != null)
                {
                    SetInfoLabel("A person with the same name already exists.");
                    return;
                }
                db.People.Add(new Person {
                    Name = newPersonName
                });
                await db.SaveChangesAsync();

                LoadPeope();
            }
        }
 public ReportService(PetsDbContext db, IMapper mapper, IPetService pet, ILocationSevices location)
 {
     this.db       = db;
     this.mapper   = mapper;
     this.pet      = pet;
     this.location = location;
 }
예제 #3
0
 private void LoadPeope()
 {
     using (var db = new PetsDbContext())
     {
         var people = db.People.ToList();
         PeopleListView.ItemsSource = people;
     }
 }
예제 #4
0
        public MainPage()
        {
            InitializeComponent();

            var fileName   = "Pets.db";
            var dbFullPath = Path.Combine(App.DbFolder, fileName);

            PetsDbContext.DataBasePath = dbFullPath;
            using (var db = new PetsDbContext())
            {
                db.Database.Migrate();
            }
        }
예제 #5
0
        private void LoadPets()
        {
            using (var db = new PetsDbContext())
            {
                var pets = db.Set <Animal>().ToList();
                PetListView.ItemsSource = pets;

                _people = db.People.ToList();
                OwnerPicker.Items.Clear();
                foreach (var person in _people)
                {
                    OwnerPicker.Items.Add(person.Name);
                }
            }
        }
예제 #6
0
        public static void Seed(PetsDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException(nameof(dbContext));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            var roleManager = serviceProvider.GetRequiredService <RoleManager <ApplicationRole> >();
            var userManager = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();

            Seed(dbContext, userManager, roleManager);
        }
예제 #7
0
        public static void Seed(PetsDbContext dbContext, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException(nameof(dbContext));
            }

            if (userManager == null)
            {
                throw new ArgumentNullException(nameof(userManager));
            }

            if (roleManager == null)
            {
                throw new ArgumentNullException(nameof(roleManager));
            }

            SeedRoles(roleManager);
            //SeedAdmin(userManager);
        }
예제 #8
0
        private async void AddPet_OnClicked(object sender, EventArgs e)
        {
            var newPetName = PetNameEntry.Text;

            if (string.IsNullOrWhiteSpace(newPetName))
            {
                SetInfoLabel("Name must not be empty.");
                return;
            }
            var ownerIndex = OwnerPicker.SelectedIndex;

            if (ownerIndex < 0)
            {
                SetInfoLabel("Select an owner.");
                return;
            }
            var    owner = _people[ownerIndex];
            Animal animal;

            if (AnimalKindPicker.SelectedIndex == 0)
            {
                animal = new Dog();
            }
            else
            {
                animal = new Platypus();
            }
            animal.Name  = newPetName;
            animal.Owner = owner;
            using (var db = new PetsDbContext())
            {
                db.People.Attach(owner);
                db.Set <Animal>().Add(animal);
                await db.SaveChangesAsync();
            }
            LoadPets();
        }
예제 #9
0
 public PetsController(PetsDbContext petsDbContext)
 {
     _petsDbContext = petsDbContext;
 }
예제 #10
0
 public AdoptionCatService(PetsDbContext db)
 {
     this.db = db;
 }
예제 #11
0
 public LocationSevices(PetsDbContext db)
 {
     this.db = db;
 }
예제 #12
0
 public PetsDbService(PetsDbContext _context)
 {
     context = _context;
 }
예제 #13
0
 public CommentService(PetsDbContext db)
 {
     this.db = db;
 }
예제 #14
0
 public DbService(PetsDbContext context)
 {
     _context = context;
 }
예제 #15
0
 public EfDeletableEntityRepository(PetsDbContext context)
     : base(context)
 {
 }
예제 #16
0
 public PetService(PetsDbContext db, IMapper mapper)
 {
     this.db     = db;
     this.mapper = mapper;
 }
예제 #17
0
 public PetsController(PetsDbContext db)
 {
     _db = db;
 }
예제 #18
0
 public EfRepository(PetsDbContext context)
 {
     this.Context = context ?? throw new ArgumentNullException(nameof(context));
     this.DbSet   = this.Context.Set <TEntity>();
 }