Esempio n. 1
0
        public void LeaveHousehold(string userId, int householdId)
        {
            UserEntity user = Store.FindByIdAsync(userId).GetAwaiter().GetResult();

            var household = user.Households.FirstOrDefault(x => x.HouseholdId == householdId);

            if (household == null)
            {
                throw new KeyNotFoundException($"User is not in this household");
            }

            user.Households.Remove(household);
            DatabaseContext.SaveChanges();
        }
Esempio n. 2
0
        public ThingDto Create(ThingDto dto)
        {
            ThingEntity entity = new ThingEntity();

            entity.Name         = dto.Name;
            entity.HouseholdId  = dto.HouseholdId;
            entity.Show         = dto.Show;
            entity.Needed       = dto.Needed;
            entity.DefaultPrice = dto.DefaultPrice;

            context.Things.Add(entity);
            context.SaveChanges();

            return(buildDto(entity));
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public PurchaseDto Create(PurchaseDto dto)
        {
            var entity = new PurchaseEntity()
            {
                ThingId  = dto.ThingId,
                MadeById = dto.MadeById,
                Price    = dto.Price,
                MadeOn   = dto.MadeOn,
            };

            context.Purchases.Add(entity);
            context.SaveChanges();

            dto.PurchaseId = entity.PurchaseId;

            throw new NotImplementedException();
        }
Esempio n. 5
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();
            }
        }
Esempio n. 6
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();
            }
        }
Esempio n. 7
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);
        }