Example #1
0
        public bool Create(DonationViewModel donation, List <string> categoriesId)
        {
            var model = new Donation();

            model.Institution      = _institutionService.Get(donation.InstitutionId.ToString());
            model.PickUpTime       = donation.PickUpDateOn.AddHours(donation.PickUpTimeOn.Hour).AddMinutes(donation.PickUpTimeOn.Hour);
            model.DonationId       = Guid.NewGuid().ToString();
            model.City             = donation.City;
            model.DonationQuantity = donation.DonationQuantity;
            model.PhoneNumber      = donation.PhoneNumber;
            model.Street           = donation.Street;
            model.ZipCode          = donation.ZipCode;
            model.PickUpComment    = donation.PickUpComment;
            model.User             = donation.User;

            _context.Donations.Add(model);
            _context.SaveChanges();
            var donationsCategory = new List <DonationCategory>();

            foreach (var item in categoriesId)
            {
                donationsCategory.Add(new DonationCategory()
                {
                    CategoryId = item, DonationId = model.DonationId, Id = Guid.NewGuid().ToString()
                });
            }
            _context.AddRange(donationsCategory);
            return(_context.SaveChanges() > 0);
        }
Example #2
0
        public ActionResult INeedHelp([Bind(Include = "NeedHelpId,FirstName,LastName,Phone,Message")] NeedHelp needHelp)
        {
            if (ModelState.IsValid)
            {
                db.NeedHelps.Add(needHelp);
                db.SaveChanges();
                return(RedirectToAction("Thank", "Home"));
            }

            return(View(needHelp));
        }
        public ActionResult Create([Bind(Include = "CanHelpId,FirstName,LastName,Email,CreditCard,CV,Amount")] CanHelp canHelp)
        {
            if (ModelState.IsValid)
            {
                db.CanHelps.Add(canHelp);
                db.SaveChanges();
                return(RedirectToAction("DonateConfirmed", new { id = canHelp.CanHelpId }));
            }

            return(View(canHelp));
        }
        public bool DoPayment(Payment payment, CharityContext context)
        {
            // get object of user that is making the payment
            var userThatPays = context.user.Where(x => x.Id == payment.userSenderId).Single();
            // get object of organization that receives the payment
            var orgThatReceives = context.organization.Where(x => x.Id == payment.organizationReceiverId).Single();

            // get their credit card objects
            try
            {
                var creditCardThatPays     = context.card.Where(x => x.Id == userThatPays.creditCardId).Single();
                var creditCardThatReceives = context.card.Where(x => x.Id == orgThatReceives.creditCardNumber).Single();
                if (creditCardThatPays.amount >= payment.amount && payment.amount > 0) // payment is possible
                {
                    creditCardThatPays.amount     -= payment.amount;
                    creditCardThatReceives.amount += payment.amount;
                    context.Add(payment);
                    context.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #5
0
        public ActionResult Test()
        {
            var db = new CharityContext();

            var t1 = new TeamMember {
                Registered = DateTime.Today, Name = "Heather C", CharityPage = "https://example.com/hc", Token = "heatherc"
            };
            var t2 = new TeamMember {
                Registered = DateTime.Today, Name = "Heather A", CharityPage = "https://example.com/ha", Token = "heathera"
            };
            var t3 = new TeamMember {
                Registered = DateTime.Today, Name = "Heather B", CharityPage = "https://example.com/hb", Token = "heatherb"
            };
            var t4 = new TeamMember {
                Registered = DateTime.Today, Name = "Donald Trump", CharityPage = "https://example.com/trump", Token = "TheDonald"
            };
            var t5 = new TeamMember {
                Registered = DateTime.Today, Name = "Tom Hanks", CharityPage = "https://example.com/tom", Token = "hanks"
            };
            var t6 = new TeamMember {
                Registered = DateTime.Today, Name = "Bill Gates", CharityPage = "https://example.com/gate", Token = "billyg"
            };
            var t7 = new TeamMember {
                Registered = DateTime.Today, Name = "Colonel Sanders", CharityPage = "https://example.com/sanders", Token = "TheColonel"
            };
            var t8 = new TeamMember {
                Registered = DateTime.Today, Name = "Oprah", CharityPage = "https://example.com/harpo", Token = "oprah"
            };

            db.Members.Add(t1);
            db.Members.Add(t2);
            db.Members.Add(t3);
            db.Members.Add(t4);
            db.Members.Add(t5);
            db.Members.Add(t6);
            db.Members.Add(t7);
            db.Members.Add(t8);

            db.SaveChanges();

            return(View("Test"));
        }
        public ActionResult SignUp(TeamMember member)
        {
            if (!ModelState.IsValid)
            {
                return(View(member));
            }

            //This is the happy path
            member.Registered = DateTime.Today;

            db.Members.Add(member);
            db.SaveChanges();

            // ViewBag was fin when we were returning a ViewResult
            //ViewBag.message = $"{member.Name} has Signed up!";

            // TempData - Lasts until it is read (piggybacks on session)
            TempData["message"] = $"{member.Name} has Signed up!";


            return(RedirectToAction("Index"));
        }
Example #7
0
 public bool Create(Category categoryModel)
 {
     _context.Categories.Add(categoryModel);
     return(_context.SaveChanges() > 0);
 }
 public bool Create(Institution institution)
 {
     _context.Institutions.Add(institution);
     return(_context.SaveChanges() > 0);
 }
 public bool Create(Donation donationModel)
 {
     _context.Donations.Add(donationModel);
     return(_context.SaveChanges() > 0);
 }
Example #10
0
 public bool Create(CategoriesForDonations cfd)
 {
     _context.CategoriesForDonation.Add(cfd);
     return(_context.SaveChanges() > 0);
 }
Example #11
0
        public void mockDB()
        {
#pragma warning disable CS0618 // Type or member is obsolete
            optionsBuilder.UseInMemoryDatabase();
#pragma warning restore CS0618 // Type or member is obsolete
            _dbContext = new CharityContext(optionsBuilder.Options);

            #region addingImages
            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"
            };

            _dbContext.image.Add(arrayOfImages[0]);
            _dbContext.image.Add(arrayOfImages[1]);
            _dbContext.image.Add(arrayOfImages[2]);
            _dbContext.image.Add(arrayOfImages[3]);
            _dbContext.image.Add(arrayOfImages[4]);
            #endregion

            #region addingAccount
            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
                };
            }
            savedAccounts = arrayOfAccounts;
            _dbContext.account.Add(arrayOfAccounts[0]);
            _dbContext.account.Add(arrayOfAccounts[1]);
            _dbContext.account.Add(arrayOfAccounts[2]);
            _dbContext.account.Add(arrayOfAccounts[3]);
            _dbContext.account.Add(arrayOfAccounts[4]);
            _dbContext.account.Add(arrayOfAccounts[0]);
            #endregion

            #region addingCards
            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"
            };

            _dbContext.card.Add(arrayOfCreditCard[0]);
            _dbContext.card.Add(arrayOfCreditCard[1]);
            _dbContext.card.Add(arrayOfCreditCard[2]);
            _dbContext.card.Add(arrayOfCreditCard[3]);
            _dbContext.card.Add(arrayOfCreditCard[4]);
            #endregion

            #region addingUsers
            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
            };

            _dbContext.user.Add(arrayOfUsers[0]);
            _dbContext.user.Add(arrayOfUsers[1]);
            _dbContext.user.Add(arrayOfUsers[2]);
            #endregion

            #region addingOrganizations
            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
            };

            _dbContext.organization.Add(arrayOfOrganizations[0]);
            _dbContext.organization.Add(arrayOfOrganizations[1]);
            #endregion

            #region adddingItems
            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
            };

            _dbContext.item.Add(arrayOfItems[0]);
            _dbContext.item.Add(arrayOfItems[1]);
            #endregion

            #region addingActions
            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, 1, 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, 3, 5, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second)
            };

            _dbContext.action.Add(arrayOfActions[0]);
            _dbContext.action.Add(arrayOfActions[1]);
            _dbContext.action.Add(arrayOfActions[2]);
            #endregion

            #region addingItemInAction
            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
            };

            _dbContext.itemInAction.Add(arrayOfItemsInActions[0]);
            _dbContext.itemInAction.Add(arrayOfItemsInActions[1]);
            _dbContext.itemInAction.Add(arrayOfItemsInActions[2
                                        ]);
            #endregion

            #region addingMessages
            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
            };

            _dbContext.message.Add(arrayOfMessages[0]);
            _dbContext.message.Add(arrayOfMessages[1]);
            _dbContext.message.Add(arrayOfMessages[2]);
            _dbContext.message.Add(arrayOfMessages[3]);
            _dbContext.message.Add(arrayOfMessages[4]);
            #endregion

            #region addingPayments
            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
            };

            _dbContext.payment.Add(arrayOfPayments[0]);
            _dbContext.payment.Add(arrayOfPayments[1]);
            _dbContext.payment.Add(arrayOfPayments[2]);
            #endregion

            #region addingProfilePosts
            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."
            };

            _dbContext.profilePosts.Add(arrayOfProfilePosts[0]);
            _dbContext.profilePosts.Add(arrayOfProfilePosts[1]);
            _dbContext.profilePosts.Add(arrayOfProfilePosts[2]);
            #endregion

            #region addingReactionsToPosts
            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
            };

            _dbContext.reactionsToPosts.Add(arrayOfReactionsToPosts[0]);
            _dbContext.reactionsToPosts.Add(arrayOfReactionsToPosts[1]);
            _dbContext.reactionsToPosts.Add(arrayOfReactionsToPosts[2]);
            #endregion

            #region addingUserParticipatingInAction
            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
            };

            _dbContext.userParticipatingInAction.Add(arrayOfUsersParticipating[0]);
            _dbContext.userParticipatingInAction.Add(arrayOfUsersParticipating[1]);
            _dbContext.userParticipatingInAction.Add(arrayOfUsersParticipating[2]);
            #endregion

            _dbContext.SaveChanges();
        }