Пример #1
0
        public ThingEntity getTestThing()
        {
            TwnContext context = new TwnContext();

            var household = context.Households.Add(new HouseholdEntity()
            {
                Address = new AddressDto()
                {
                    Address1 = "TestStreet 1",
                    City     = "TestCity",
                    Country  = "DK",
                    PostCode = "9000"
                },
                Name = "TestNameHousehold"
            });

            double price = new Random().Next(0, 1000);
            var    thing = new ThingEntity()
            {
                Needed       = true,
                Name         = "TestThing",
                Household    = household,
                DefaultPrice = price
            };

            var thingEntity = context.Things.Add(thing);

            context.Households.Add(household);
            //using (context)
            //{
            //    context.SaveChanges();
            //}
            return(thingEntity);
        }
Пример #2
0
        public WishEntity getTestWish()
        {
            TwnContext context = new TwnContext();

            var user = context.Users.Add(new UserEntity()
            {
                Email       = "[email protected]",
                FName       = "TestNameUser",
                Username    = "******",
                PhoneNumber = "0944587369",
                LName       = "larry",
                PenisSize   = 123123f
            });

            double price = new Random().Next(0, 200);
            var    wish  = new WishEntity()
            {
                MaxPrice  = price,
                ExtraPay  = 7,
                GrantedOn = DateTime.Today,
                User      = user,
                Name      = "noose"
            };

            var wishEntity = context.Wishes.Add(wish);

            context.Users.Add(user);
            using (context)
            {
                context.SaveChanges();
            }
            return(wishEntity);
        }
Пример #3
0
        public static WishLogic GetMockeddLogic()
        {
            TwnContext context = new TwnContext();

            WishLogic logic = new WishLogic();

            logic.InjectDatabaseContext(context);
            return(logic);
        }
Пример #4
0
        private void cleanup(int id)
        {
            WishEntity wish;

            using (TwnContext context = new TwnContext())
            {
                wish = context.Wishes.Find(id);
                context.Wishes.Remove(wish);
                context.Users.Remove(context.Users.Find(wish.UserId));
                context.SaveChanges();
            }
        }
Пример #5
0
        private void cleanup(ICollection <HouseholdEntity> householdList)
        {
            using (TwnContext context = new TwnContext())
            {
                foreach (HouseholdEntity household in householdList.ToList())
                {
                    foreach (ThingEntity te in household.Things.ToList())
                    {
                        if (context.Things != null)
                        {
                            try
                            {
                                context.Things.Remove(te);
                            }
                            catch (System.InvalidOperationException e)
                            {
                                // do nothing
                            }
                        }
                    }

                    foreach (UserEntity ue in household.Users.ToList())
                    {
                        if (context.Users != null)
                        {
                            try
                            {
                                context.Users.Remove(ue);
                            }
                            catch (System.InvalidOperationException e)
                            {
                                // do nothing
                            }
                        }
                    }

                    try
                    {
                        context.Households.Remove(household);
                    }
                    catch (System.InvalidOperationException e)
                    {
                        // do nothing
                    }
                }
                context.SaveChanges();
            }
        }
Пример #6
0
 public void InjectDatabaseContext(TwnContext context)
 {
     DatabaseContext = context;
 }
Пример #7
0
 public WishLogic()
 {
     DatabaseContext = new TwnContext();
 }
Пример #8
0
 public PurchaseDaLogic(TwnContext context, string userId)
 {
     this.context = context;
     this.userId  = userId;
 }
Пример #9
0
 public HouseholdDaLogic(TwnContext context, string userId)
 {
     this.userId     = userId;
     DatabaseContext = new TwnContext();
     thingDaLogic    = new ThingDaLogic(context, userId);
 }
Пример #10
0
        public ICollection <HouseholdEntity> addTestHousehold()
        {
            TwnContext context = new TwnContext();

            // add a hosuehold
            var household = context.Households.Add(new HouseholdEntity()
            {
                Address = new AddressDto()
                {
                    Address1 = "Rostrupsvej 15",
                    City     = "Aalborg",
                    Country  = "DK",
                    PostCode = "9000"
                },
                Name = "ShoulderShoulderShoulderShoulder"
            });

            var household1 = context.Households.Add(new HouseholdEntity()
            {
                Address = new AddressDto()
                {
                    Address1 = "Seklagervej 8",
                    City     = "Aalborg",
                    Country  = "DK",
                    PostCode = "9000"
                },
                Name = "UgandanCamp"
            });

            // add thing 1
            var thing1 = context.Things.Add(new ThingEntity()
            {
                Needed       = true,
                Name         = "ToothpasteTest1",
                Household    = household,
                DefaultPrice = 189
            });

            // add thing 2
            var thing2 = context.Things.Add(new ThingEntity()
            {
                Needed       = true,
                Name         = "BreadcrumbsTest2",
                Household    = household,
                DefaultPrice = 20
            });

            //  add things to the lsit
            var thingList = new List <ThingEntity>();

            thingList.Add(thing1);
            thingList.Add(thing2);

            // add household to the set
            var hashSet = new HashSet <HouseholdEntity>();

            hashSet.Add(household);

            // add a user1
            var user1 = context.Users.Add(new UserEntity()
            {
                Email       = "*****@*****.**",
                Username    = "******",
                PenisSize   = 10.0f,
                FName       = "Us",
                LName       = "Er",
                PhoneNumber = "0987654321",
                Households  = hashSet
            });

            // add a user2
            var user2 = context.Users.Add(new UserEntity()
            {
                Email       = "*****@*****.**",
                Username    = "******",
                PenisSize   = 20.0f,
                FName       = "Us",
                LName       = "Er",
                PhoneNumber = "1234567890",
                Households  = hashSet
            });

            // add users to the list
            var userList = new List <UserEntity>();

            userList.Add(user1);
            userList.Add(user2);

            // update user and thing in household
            household.Users  = userList;
            household.Things = thingList;

            using (context)
            {
                context.SaveChanges();
            }
            // list of households to return
            var householdList = new List <HouseholdEntity>();

            householdList.Add(household);
            householdList.Add(household1);
            return(householdList);
        }
Пример #11
0
 public ThingDaLogic(TwnContext context, string userId)
 {
     this.context = context;
     this.userId  = userId;
 }
Пример #12
0
 public HouseholdApiController()
 {
     context        = TwnContext.Create();
     householdLogic = new HouseholdDaLogic(context, User.Identity.GetUserId());
 }