Beispiel #1
0
 public void Add(User entity)
 {
     db.Users.Add(entity);
     db.SaveChanges();
 }
Beispiel #2
0
 public User UpdateUser(User user)
 {
     _ctx.Entry(user).State = EntityState.Modified;
     _ctx.SaveChanges();
     return(user);
 }
 public bool Insert(PetCategory dto)
 {
     _context.PetCategory.Add(dto);
     return(_context.SaveChanges() != 0);
 }
 public void SeedDb(PetShopContext ctx)
 {
     SeedOwners(ctx);
     ctx.SaveChanges();
 }
 public Owner Create(Owner owner)
 {
     _context.Owners.Attach(owner).State = EntityState.Added;
     _context.SaveChanges();
     return(owner);
 }
Beispiel #6
0
 public Pet AddPet(Pet pet)
 {
     _context.Attach(pet).State = EntityState.Added;
     _context.SaveChanges();
     return(pet);
 }
Beispiel #7
0
 public bool Delete(Favorite dto)
 {
     _context.Favorite.Remove(dto);
     return(_context.SaveChanges() != 0);
 }
 public bool Insert(AccessoryTransactionRel dto)
 {
     _context.AccessoryTransactionRel.Add(dto);
     return(_context.SaveChanges() != 0);
 }
Beispiel #9
0
        public static void SeedDB(PetShopContext ctx)
        {
            ctx.Database.EnsureDeleted();
            ctx.Database.EnsureCreated();

            var owner1 = ctx.Owners.Add(new Owner()
            {
                FirstName   = "Lotte",
                LastName    = "Tubæk",
                Address     = "Rosenparken 53",
                Email       = "*****@*****.**",
                PhoneNumber = "23313226"
            }
                                        ).Entity;

            var owner2 = ctx.Owners.Add(new Owner()
            {
                FirstName   = "Mikael",
                LastName    = "Fabrisous",
                Address     = "Gammelmandvej 53",
                Email       = "*****@*****.**",
                PhoneNumber = "2334334226"
            }
                                        ).Entity;


            var pet1 = ctx.Pets.Add(new Pet()
            {
                name          = "Daniel",
                type          = "Goat",
                color         = "Ugly",
                price         = 2400,
                previousOwner = owner1
            });

            var pet2 = ctx.Pets.Add(new Pet()
            {
                name          = "Misser",
                type          = "Hund",
                color         = "Brun",
                price         = 7699,
                previousOwner = owner2
            });

            string password = "******";

            byte[] passwordHashJoe, passwordSaltJoe, passwordHashAnn, passwordSaltAnn;
            CreatePasswordHash(password, out passwordHashJoe, out passwordSaltJoe);
            CreatePasswordHash(password, out passwordHashAnn, out passwordSaltAnn);

            List <User> users = new List <User>
            {
                new User {
                    Username     = "******",
                    PasswordHash = passwordHashJoe,
                    PasswordSalt = passwordSaltJoe,
                    IsAdmin      = false
                },
                new User {
                    Username     = "******",
                    PasswordHash = passwordHashAnn,
                    PasswordSalt = passwordSaltAnn,
                    IsAdmin      = true
                }
            };

            ctx.Users.AddRange(users);
            ctx.SaveChanges();
        }
 public Pet Create(Pet pet)
 {
     _ctx.Attach(pet).State = EntityState.Added;
     _ctx.SaveChanges();
     return(pet);
 }
Beispiel #11
0
 /// <summary>
 /// Adds the owner to the DB.
 /// </summary>
 /// <param name="owner"></param>
 /// <returns>Owner with id given by DB.</returns>
 public Owner CreateOwner(Owner owner)
 {
     _ctx.Attach(owner).State = EntityState.Added;
     _ctx.SaveChanges();
     return(owner);
 }
Beispiel #12
0
        public static void Seed(PetShopContext ctx)
        {
            Pet pet1 = new Pet
            {
                name          = "Rex",
                type          = PetTypes.Dog,
                birthDate     = new DateTime(2017, 4, 20),
                soldDate      = new DateTime(2017, 6, 25),
                color         = "Brownish",
                price         = 275,
                ownersHistory = new List <PetOwner>()
            };
            Pet pet2 = new Pet
            {
                name          = "Spoofy",
                type          = PetTypes.Cat,
                birthDate     = new DateTime(2018, 3, 10),
                soldDate      = new DateTime(2018, 3, 30),
                color         = "White and black",
                price         = 550,
                ownersHistory = new List <PetOwner>()
            };
            Owner owner1 = new Owner
            {
                firstName  = "Simon",
                lastName   = "Kjær",
                address    = "Stengårdsvej 12",
                petHistory = new List <PetOwner>()
            };
            Owner owner2 = new Owner
            {
                firstName  = "Levis",
                lastName   = "Kjongaard",
                address    = "Hjertingvej 5",
                petHistory = new List <PetOwner>()
            };



            owner1 = ctx.Owners.Add(owner1).Entity;
            owner2 = ctx.Owners.Add(owner2).Entity;

            PetOwner PetOwner1 = new PetOwner
            {
                Owner = owner1
            };

            PetOwner PetOwner2 = new PetOwner
            {
                Owner = owner2
            };

            PetOwner PetOwner3 = new PetOwner
            {
                Owner = owner1
            };

            pet1.ownersHistory.Add(PetOwner1);
            pet1.ownersHistory.Add(PetOwner2);
            pet2.ownersHistory.Add(PetOwner3);

            ctx.Pets.Add(pet1);
            ctx.Pets.Add(pet2);



            ctx.SaveChanges();
        }
Beispiel #13
0
 public void Add(User entity)
 {
     _ctx.Users.Add(entity);
     _ctx.SaveChanges();
 }
Beispiel #14
0
 public void UpdateUser(User user)
 {
     _ctx.Attach(user).State = EntityState.Modified;
     _ctx.SaveChanges();
 }
Beispiel #15
0
 public void CreatePet(Pet pet)
 {
     _ctx.Add(pet);
     _ctx.SaveChanges();
 }
Beispiel #16
0
        public ActionResult Create([Bind(Include = "Name,Price,Description,Volume")] Item item, string Animal, string Brand, string Subcategory, string Category)
        {
            if (String.IsNullOrEmpty(Animal) || String.IsNullOrEmpty(Brand) ||
                String.IsNullOrEmpty(Subcategory) || String.IsNullOrEmpty(Animal) ||
                String.IsNullOrEmpty(item.Name) || String.IsNullOrEmpty(item.Description) ||
                (item.Price == null) || String.IsNullOrEmpty(item.Volume))
            {
                ModelState.AddModelError(String.Empty, "Values can't be null");
            }
            if (ModelState.IsValid)
            {
                var animal = db.Animals.Where(a => a.Name == Animal).FirstOrDefault();
                if (animal == null)
                {
                    animal = db.Animals.Add(new Models.Animal()
                    {
                        Name = Animal, CreatedOn = DateTime.UtcNow
                    });
                    db.SaveChanges();
                }
                var brand = db.Brands.Where(a => a.Name == Brand).FirstOrDefault();
                if (brand == null)
                {
                    brand = db.Brands.Add(new Models.Brand()
                    {
                        Name = Brand, CreatedOn = DateTime.UtcNow
                    });
                    db.SaveChanges();
                }
                var category = db.ItemCategories.Where(a => a.Name == Category).FirstOrDefault();
                if (category == null)
                {
                    category = db.ItemCategories.Add(new Models.ItemCategory()
                    {
                        Name = Category, CreatedOn = DateTime.UtcNow
                    });
                    db.SaveChanges();
                }
                var subcategory = db.ItemSubcategories.Where(a => a.Name == Subcategory).FirstOrDefault();
                if (subcategory == null)
                {
                    subcategory = db.ItemSubcategories.Add(new Models.ItemSubcategory()
                    {
                        Name = Category, CreatedOn = DateTime.UtcNow, ItemCategory = category
                    });
                    db.SaveChanges();
                }
                item.Animal          = animal;
                item.Brand           = brand;
                item.ItemSubcategory = subcategory;
                item.CreatedOn       = DateTime.UtcNow;
                db.Items.Add(item);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Animals           = db.Animals.Select(a => a.Name).ToList();
            ViewBag.Brands            = db.Brands.Select(a => a.Name).ToList();
            ViewBag.ItemSubcategories = db.ItemSubcategories.Select(a => a.Name).ToList();
            ViewBag.Itemcategories    = db.ItemCategories.Select(a => a.Name).ToList();
            return(View(item));
        }
Beispiel #17
0
 public void CreateOwner(Owner owner)
 {
     _ctx.Add(owner);
     _ctx.SaveChanges();
 }
Beispiel #18
0
 public void Create(User user)
 {
     _ctx.Users.Attach(user).State = EntityState.Added;
     _ctx.SaveChanges();
 }
 public Color Create(Color color)
 {
     _ctx.Colors.Attach(color).State = EntityState.Added;
     _ctx.SaveChanges();
     return(color);
 }
Beispiel #20
0
 public void AddUser(User entity)
 {
     _context.Users.Add(entity);
     _context.SaveChanges();
 }
Beispiel #21
0
 public Pet CreateNewPetRepo(Pet newPet)
 {
     _ctx.Attach(newPet).State = EntityState.Added;
     _ctx.SaveChanges();
     return(newPet);
 }
Beispiel #22
0
 public Owner CreateOwner(Owner owner)
 {
     _ctx.Add(owner);
     _ctx.SaveChanges();
     return(owner);
 }
Beispiel #23
0
        static void Main()
        {
            PetShopContext context = new PetShopContext();

            context.SaveChanges();
        }
 public User Add(User entity)
 {
     db.Users.Add(entity);
     db.SaveChanges();
     return(entity);
 }
Beispiel #25
0
 public void Edit(User entity)
 {
     db.Entry(entity).State = EntityState.Modified;
     db.SaveChanges();
 }
Beispiel #26
0
 public bool Insert(AccessoryCategory dto)
 {
     _context.AccessoryCategory.Add(dto);
     return(_context.SaveChanges() != 0);
 }
Beispiel #27
0
 public Pet CreatePet(Pet pet)
 {
     _ctx.Add(pet);
     _ctx.SaveChanges();
     return(pet);
 }