Example #1
0
    public List <ProfilePost> GetPostsOnProfile(User u)
    {
        var list = ProfilePosts.Where(pp => pp.u == u).Include(c => c.author).ToList();

        list.Reverse();
        return(list);
    }
Example #2
0
    public void makeProfilePost(string post, String on, String author)
    {
        var profileOwner = GetUserByName(on);
        var msgAuthor    = GetUserByName(author);

        ProfilePosts.Add(new ProfilePost {
            post = post, u = profileOwner, author = msgAuthor
        });
        SaveChanges();
    }
Example #3
0
 public ProfilePost GetProfilePostById(int i)
 {
     return(ProfilePosts.Where(p => p.id == i).FirstOrDefault());
 }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <Account>(account =>
            {
                account.Property(e => e.username).IsRequired();
                account.Property(e => e.password).IsRequired();
                account.Property(e => e.isUser).IsRequired();
            });


            #region ArrayOfImages
            Image[] arrayOfImages = new Image[5];
            arrayOfImages[0] = new Image {
                Id = Guid.NewGuid(), Path = "https://i.pinimg.com/originals/df/bd/df/dfbddf7c530ab5f4cd70154409651f9d.jpg"
            };
            arrayOfImages[1] = new Image {
                Id = Guid.NewGuid(), Path = "http://bestdayevereducation.com/uploads/images/FreeVector-Spongebob-Squarepants-Vector.jpg"
            };
            arrayOfImages[2] = new Image {
                Id = Guid.NewGuid(), Path = "https://arc-anglerfish-arc2-prod-elcomercio.s3.amazonaws.com/public/AVA6IKPJNBAS7JZ3CREUNY64K4.jpg"
            };
            arrayOfImages[3] = new Image {
                Id = Guid.NewGuid(), Path = "https://upload.wikimedia.org/wikipedia/commons/thumb/8/80/Cartoon_Network_2010_logo.svg/2000px-Cartoon_Network_2010_logo.svg.png"
            };
            arrayOfImages[4] = new Image {
                Id = Guid.NewGuid(), Path = "https://cdn.vox-cdn.com/thumbor/m6_h4h6uHuJeZCnWTCz7anTlVJA=/0x0:1920x1080/1200x800/filters:focal(807x387:1113x693)/cdn.vox-cdn.com/uploads/chorus_image/image/60720529/disneyplus.0.4.jpg"
            };
            #endregion

            #region ArrayOfAccounts

            Account[] arrayOfAccounts = new Account[5];
            using (var sha256 = SHA256.Create())
            {
                // Send a sample text to hash.
                var pass1 = sha256.ComputeHash(Encoding.UTF8.GetBytes("samplepass1"));
                var pass2 = sha256.ComputeHash(Encoding.UTF8.GetBytes("samplepass2"));
                var pass3 = sha256.ComputeHash(Encoding.UTF8.GetBytes("samplepass3"));
                var pass4 = sha256.ComputeHash(Encoding.UTF8.GetBytes("samplepass4"));
                var pass5 = sha256.ComputeHash(Encoding.UTF8.GetBytes("samplepass5"));
                // Get the hashed string.
                var hash1 = BitConverter.ToString(pass1).Replace("-", "").ToLower();
                var hash2 = BitConverter.ToString(pass2).Replace("-", "").ToLower();
                var hash3 = BitConverter.ToString(pass3).Replace("-", "").ToLower();
                var hash4 = BitConverter.ToString(pass4).Replace("-", "").ToLower();
                var hash5 = BitConverter.ToString(pass5).Replace("-", "").ToLower();

                // Print the string.
                // Console.WriteLine(hash);

                arrayOfAccounts[0] = new Account {
                    Id = Guid.NewGuid(), username = "******", password = hash1, email = "*****@*****.**", isUser = true, imageId = arrayOfImages[0].Id
                };
                arrayOfAccounts[1] = new Account {
                    Id = Guid.NewGuid(), username = "******", password = hash2, email = "*****@*****.**", isUser = true, imageId = arrayOfImages[1].Id
                };
                arrayOfAccounts[2] = new Account {
                    Id = Guid.NewGuid(), username = "******", password = hash3, email = "*****@*****.**", isUser = true, imageId = arrayOfImages[2].Id
                };
                arrayOfAccounts[3] = new Account {
                    Id = Guid.NewGuid(), username = "******", password = hash4, email = "*****@*****.**", isUser = false, imageId = arrayOfImages[3].Id
                };
                arrayOfAccounts[4] = new Account {
                    Id = Guid.NewGuid(), username = "******", password = hash5, email = "*****@*****.**", isUser = false, imageId = arrayOfImages[4].Id
                };
            }
            #endregion

            #region ArrayOfCards
            Card[] arrayOfCreditCard = new Card[5];
            arrayOfCreditCard[0] = new Card {
                Id = Guid.NewGuid(), bankName = "Karntner Sparkasse", dateOfExpiry = new DateTime(2020, 5, 15), amount = 100, creditCardNumber = "1234567891011121"
            };
            arrayOfCreditCard[1] = new Card {
                Id = Guid.NewGuid(), bankName = "Karntner Sparkasse", dateOfExpiry = new DateTime(2021, 7, 20), amount = 50, creditCardNumber = "3141516171819202"
            };
            arrayOfCreditCard[2] = new Card {
                Id = Guid.NewGuid(), bankName = "Karntner Ladesbank Raiffeisen", dateOfExpiry = new DateTime(2020, 2, 20), amount = 150, creditCardNumber = "1222324252627282"
            };
            arrayOfCreditCard[3] = new Card {
                Id = Guid.NewGuid(), bankName = "Austria Bank", dateOfExpiry = new DateTime(2021, 1, 15), amount = 200, creditCardNumber = "9303132333435363"
            };
            arrayOfCreditCard[4] = new Card {
                Id = Guid.NewGuid(), bankName = "Austria Bank", dateOfExpiry = new DateTime(2020, 3, 14), amount = 55, creditCardNumber = "7383940414243444"
            };
            #endregion

            #region ArrayOfUsers
            User[] arrayOfUsers = new User[3];
            arrayOfUsers[0] = new User {
                Id = Guid.NewGuid(), firstName = "Foo", lastName = "Bar", gender = 'M', dateOfBirth = new DateTime(1997, 1, 5), creditCardId = arrayOfCreditCard[0].Id, UserAccount = arrayOfAccounts[0].Id
            };
            arrayOfUsers[1] = new User {
                Id = Guid.NewGuid(), firstName = "John", lastName = "Doe", gender = 'F', dateOfBirth = new DateTime(1980, 11, 10), creditCardId = arrayOfCreditCard[1].Id, UserAccount = arrayOfAccounts[1].Id
            };
            arrayOfUsers[2] = new User {
                Id = Guid.NewGuid(), firstName = "Nicholas", lastName = "Cage", gender = 'M', dateOfBirth = new DateTime(1970, 5, 15), creditCardId = arrayOfCreditCard[2].Id, UserAccount = arrayOfAccounts[2].Id
            };
            #endregion

            #region ArrayOfOrganizations
            Organization[] arrayOfOrganizations = new Organization[2];
            arrayOfOrganizations[0] = new Organization {
                Id = Guid.NewGuid(), dateOfFounding = new DateTime(2015, 5, 3), name = "CharityOrg1", description = "This is a sample organization for doing something which is good", UserAccount = arrayOfAccounts[3].Id, creditCardNumber = arrayOfCreditCard[3].Id
            };
            arrayOfOrganizations[1] = new Organization {
                Id = Guid.NewGuid(), dateOfFounding = new DateTime(2019, 10, 10), name = "CharityOrg2", description = "This organization does charity actions which are great!", UserAccount = arrayOfAccounts[4].Id, creditCardNumber = arrayOfCreditCard[4].Id
            };
            #endregion

            #region ArrayOfActions
            CharityAction[] arrayOfActions = new CharityAction[3];
            arrayOfActions[0] = new CharityAction {
                Id = Guid.NewGuid(), actionType = false, description = "This is a generic action where you sign up to participate", name = "Race for cure", organizationId = arrayOfOrganizations[0].Id, creationDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), startDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), endDateTime = new DateTime(2020, 2, 5, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second)
            };
            arrayOfActions[1] = new CharityAction {
                Id = Guid.NewGuid(), actionType = true, description = "This is a generic action where people donate stuff", name = "Fundraising for children without parents", organizationId = arrayOfOrganizations[0].Id, creationDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), startDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), endDateTime = new DateTime(2020, 2, 5, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second)
            };
            arrayOfActions[2] = new CharityAction {
                Id = Guid.NewGuid(), actionType = true, description = "This is another action where people donate stuff", name = "Another fundraising", organizationId = arrayOfOrganizations[1].Id, creationDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), startDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), endDateTime = new DateTime(2020, 2, 5, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second)
            };
            #endregion

            #region ArrayOfItems
            Item[] arrayOfItems = new Item[2];
            arrayOfItems[0] = new Item {
                Id = Guid.NewGuid(), name = "Basketball", description = "A ball for playing basketball", value = 50, userDonatedId = arrayOfUsers[0].Id
            };
            arrayOfItems[1] = new Item {
                Id = Guid.NewGuid(), name = "Makeup", description = "Some spare makeup I donate", value = 150, userDonatedId = arrayOfUsers[1].Id
            };
            #endregion

            #region ArrayOfItemInAction
            ItemInAction[] arrayOfItemsInActions = new ItemInAction[3];
            arrayOfItemsInActions[0] = new ItemInAction {
                Id = Guid.NewGuid(), actionId = arrayOfActions[1].Id, itemId = arrayOfItems[0].Id
            };
            arrayOfItemsInActions[1] = new ItemInAction {
                Id = Guid.NewGuid(), actionId = arrayOfActions[1].Id, itemId = arrayOfItems[0].Id
            };
            arrayOfItemsInActions[2] = new ItemInAction {
                Id = Guid.NewGuid(), actionId = arrayOfActions[2].Id, itemId = arrayOfItems[1].Id
            };
            #endregion

            #region ArrayOfMessages
            Messages[] arrayOfMessages = new Messages[5];
            arrayOfMessages[0] = new Messages {
                Id = Guid.NewGuid(), sendingTime = new DateTime(2019, 11, 20, 22, 24, 30), message = "May I participate in your action :)", userSenderId = arrayOfUsers[0].Id, organizationReceiverId = arrayOfOrganizations[0].Id
            };
            arrayOfMessages[1] = new Messages {
                Id = Guid.NewGuid(), sendingTime = new DateTime(2019, 11, 20, 23, 25, 30), message = "Of course you can. All the best.", organizationSenderId = arrayOfOrganizations[0].Id, userReceiverId = arrayOfUsers[0].Id
            };
            arrayOfMessages[2] = new Messages {
                Id = Guid.NewGuid(), sendingTime = new DateTime(2019, 10, 15, 20, 00, 00), message = "How are you my friend?", userSenderId = arrayOfUsers[1].Id, userReceiverId = arrayOfUsers[2].Id
            };
            arrayOfMessages[3] = new Messages {
                Id = Guid.NewGuid(), sendingTime = new DateTime(2019, 10, 15, 21, 00, 00), message = "All is well, thank you, and you?", userSenderId = arrayOfUsers[2].Id, userReceiverId = arrayOfUsers[1].Id
            };
            arrayOfMessages[4] = new Messages {
                Id = Guid.NewGuid(), sendingTime = new DateTime(2019, 10, 15, 22, 00, 00), message = "I am fine, thanks", userSenderId = arrayOfUsers[1].Id, userReceiverId = arrayOfUsers[2].Id
            };
            #endregion

            #region ArrayOfPayments
            Payment[] arrayOfPayments = new Payment[3];
            arrayOfPayments[0] = new Payment {
                Id = Guid.NewGuid(), amount = 100, organizationReceiverId = arrayOfOrganizations[0].Id, userSenderId = arrayOfUsers[0].Id
            };
            arrayOfPayments[1] = new Payment {
                Id = Guid.NewGuid(), amount = 100, organizationReceiverId = arrayOfOrganizations[1].Id, userSenderId = arrayOfUsers[0].Id
            };
            arrayOfPayments[2] = new Payment {
                Id = Guid.NewGuid(), amount = 100, organizationReceiverId = arrayOfOrganizations[0].Id, userSenderId = arrayOfUsers[1].Id
            };
            #endregion

            #region ArrayOfProfilePosts
            ProfilePosts[] arrayOfProfilePosts = new ProfilePosts[3];
            arrayOfProfilePosts[0] = new ProfilePosts {
                Id = Guid.NewGuid(), actionId = arrayOfActions[0].Id, userId = arrayOfUsers[0].Id, message = "I just did something in this action"
            };
            arrayOfProfilePosts[1] = new ProfilePosts {
                Id = Guid.NewGuid(), actionId = arrayOfActions[1].Id, userId = arrayOfUsers[1].Id, message = "I did something too"
            };
            arrayOfProfilePosts[2] = new ProfilePosts {
                Id = Guid.NewGuid(), actionId = arrayOfActions[2].Id, userId = arrayOfUsers[2].Id, message = "Normally, I did as well."
            };
            #endregion

            #region ArrayOfReactionsToPosts
            ReactionsToPosts[] arrayOfReactionsToPosts = new ReactionsToPosts[3];
            arrayOfReactionsToPosts[0] = new ReactionsToPosts {
                Id = Guid.NewGuid(), postId = arrayOfProfilePosts[0].Id, liked = true, commented = false, userReactedId = arrayOfUsers[2].Id
            };
            arrayOfReactionsToPosts[1] = new ReactionsToPosts {
                Id = Guid.NewGuid(), postId = arrayOfProfilePosts[1].Id, liked = true, commented = true, userReactedId = arrayOfUsers[0].Id, commentText = "Glad you did that!"
            };
            arrayOfReactionsToPosts[2] = new ReactionsToPosts {
                Id = Guid.NewGuid(), postId = arrayOfProfilePosts[2].Id, liked = true, commented = false, userReactedId = arrayOfUsers[1].Id
            };
            #endregion

            #region ArrayOfUserParticipatingInAction
            UserParticipatingInAction[] arrayOfUsersParticipating = new UserParticipatingInAction[3];
            arrayOfUsersParticipating[0] = new UserParticipatingInAction {
                Id = Guid.NewGuid(), actionId = arrayOfActions[0].Id, userId = arrayOfUsers[0].Id
            };
            arrayOfUsersParticipating[1] = new UserParticipatingInAction {
                Id = Guid.NewGuid(), actionId = arrayOfActions[1].Id, userId = arrayOfUsers[1].Id
            };
            arrayOfUsersParticipating[2] = new UserParticipatingInAction {
                Id = Guid.NewGuid(), actionId = arrayOfActions[2].Id, userId = arrayOfUsers[2].Id
            };
            #endregion

            #region ImageSeed
            modelBuilder.Entity <Image>().HasData(arrayOfImages[0]);
            modelBuilder.Entity <Image>().HasData(arrayOfImages[1]);
            modelBuilder.Entity <Image>().HasData(arrayOfImages[2]);
            modelBuilder.Entity <Image>().HasData(arrayOfImages[3]);
            modelBuilder.Entity <Image>().HasData(arrayOfImages[4]);
            #endregion

            #region AccountSeed
            modelBuilder.Entity <Account>().HasData(arrayOfAccounts[0]);
            modelBuilder.Entity <Account>().HasData(arrayOfAccounts[1]);
            modelBuilder.Entity <Account>().HasData(arrayOfAccounts[2]);
            modelBuilder.Entity <Account>().HasData(arrayOfAccounts[3]);
            modelBuilder.Entity <Account>().HasData(arrayOfAccounts[4]);
            #endregion

            #region CardSeed
            modelBuilder.Entity <Card>().HasData(arrayOfCreditCard[0]);
            modelBuilder.Entity <Card>().HasData(arrayOfCreditCard[1]);
            modelBuilder.Entity <Card>().HasData(arrayOfCreditCard[2]);
            modelBuilder.Entity <Card>().HasData(arrayOfCreditCard[3]);
            modelBuilder.Entity <Card>().HasData(arrayOfCreditCard[4]);
            #endregion

            #region UserSeed
            modelBuilder.Entity <User>().HasData(arrayOfUsers[0]);
            modelBuilder.Entity <User>().HasData(arrayOfUsers[1]);
            modelBuilder.Entity <User>().HasData(arrayOfUsers[2]);
            #endregion

            #region OrganizationSeed
            modelBuilder.Entity <Organization>().HasData(arrayOfOrganizations[0]);
            modelBuilder.Entity <Organization>().HasData(arrayOfOrganizations[1]);
            #endregion

            #region ActionSeed
            modelBuilder.Entity <CharityAction>().HasData(arrayOfActions[0]);
            modelBuilder.Entity <CharityAction>().HasData(arrayOfActions[1]);
            modelBuilder.Entity <CharityAction>().HasData(arrayOfActions[2]);
            #endregion

            #region ItemSeed
            modelBuilder.Entity <Item>().HasData(arrayOfItems[0]);
            modelBuilder.Entity <Item>().HasData(arrayOfItems[1]);
            #endregion

            #region ItemInActionSeed
            modelBuilder.Entity <ItemInAction>().HasData(arrayOfItemsInActions[0]);
            modelBuilder.Entity <ItemInAction>().HasData(arrayOfItemsInActions[1]);
            modelBuilder.Entity <ItemInAction>().HasData(arrayOfItemsInActions[2]);
            #endregion

            #region MessagesSeed
            modelBuilder.Entity <Messages>().HasData(arrayOfMessages[0]);
            modelBuilder.Entity <Messages>().HasData(arrayOfMessages[1]);
            modelBuilder.Entity <Messages>().HasData(arrayOfMessages[2]);
            modelBuilder.Entity <Messages>().HasData(arrayOfMessages[3]);
            modelBuilder.Entity <Messages>().HasData(arrayOfMessages[4]);
            #endregion

            #region PaymentSeed
            modelBuilder.Entity <Payment>().HasData(arrayOfPayments[0]);
            modelBuilder.Entity <Payment>().HasData(arrayOfPayments[1]);
            modelBuilder.Entity <Payment>().HasData(arrayOfPayments[2]);
            #endregion

            #region ProfilePostsSeed
            modelBuilder.Entity <ProfilePosts>().HasData(arrayOfProfilePosts[0]);
            modelBuilder.Entity <ProfilePosts>().HasData(arrayOfProfilePosts[1]);
            modelBuilder.Entity <ProfilePosts>().HasData(arrayOfProfilePosts[2]);
            #endregion

            #region ReactionsToPostsSeed
            modelBuilder.Entity <ReactionsToPosts>().HasData(arrayOfReactionsToPosts[0]);
            modelBuilder.Entity <ReactionsToPosts>().HasData(arrayOfReactionsToPosts[1]);
            modelBuilder.Entity <ReactionsToPosts>().HasData(arrayOfReactionsToPosts[2]);
            #endregion

            #region UserParticipatingInActionSeed
            modelBuilder.Entity <UserParticipatingInAction>().HasData(arrayOfUsersParticipating[0]);
            modelBuilder.Entity <UserParticipatingInAction>().HasData(arrayOfUsersParticipating[1]);
            modelBuilder.Entity <UserParticipatingInAction>().HasData(arrayOfUsersParticipating[2]);
            #endregion
        }