public ActionResult List()
        {
            //using view model to view donations
            ListDonation ViewModel = new ListDonation();

            //debugging to see if this controller works
            Debug.WriteLine("Here");

            //URL string for browser
            string url = "DonationData/getdonations";

            // Sending HHTP request and getting a http response
            HttpResponseMessage response = client.GetAsync(url).Result;

            //if the response works show alist of donations
            if (response.IsSuccessStatusCode)
            {
                IEnumerable <DonationDto> allDonations = response.Content.ReadAsAsync <IEnumerable <DonationDto> >().Result;

                //return View(Donations);

                ViewModel.alldonations = allDonations;
                return(View(ViewModel));
            }
            else
            {
                //else the call failed return "error" string
                return(RedirectToAction("Error"));
            }
        }
        public IHttpActionResult GetAllDonations()
        {
            //List of donations
            List <Donation> Donations = db.donations.ToList();
            //using view model :: show donation
            List <ListDonation> DonationDtos = new List <ListDonation> {
            };

            //information to be displayed
            foreach (var Donation in Donations)
            {
                ListDonation donation = new ListDonation();

                //getting events from the events table and linking it to the donations table
                Event Event = db.events
                              .Where(e => e.Donations.Any(d => d.EventId == Donation.EventId))
                              .FirstOrDefault();

                //now calling the events dto to fetch the information to list
                EventDto NewEvent = new EventDto
                {
                    EventId = Event.EventId,
                    Title   = Event.Title
                };

                //now calling the donations dto to fetch the data
                DonationDto NewDonation = new DonationDto
                {
                    donationId  = Donation.donationId,
                    firstName   = Donation.firstName,
                    lastName    = Donation.lastName,
                    email       = Donation.email,
                    phoneNumber = Donation.phoneNumber,
                    amount      = Donation.amount,
                    //add event id
                    EventId = Donation.EventId,
                };

                donation.Event = NewEvent;
                DonationDtos.Add(donation);
            }

            return(Ok(DonationDtos));
        }
Esempio n. 3
0
        public IHttpActionResult GetDonationInfo()
        {
            //Join three tables
            //SELECT * FROM Donations, Users, Departments WHERE Donations.UserId = Users.UserId AND Donations.DepartmentId = Departments.DepartmentId
            var AllInfos = db.Donations
                           .Include(d => d.ApplicationUser)
                           .Include(d => d.Department)
                           .ToList();

            //Initialize object to have all donation related data
            List <ListDonation> ModelView = new List <ListDonation> {
            };

            /*
             * List<DonationDto> DonationDtos = new List<DonationDto>();
             * List<ApplicationUserDto> UserDtos = new List<ApplicationUserDto>();
             * List<DepartmentDto> DepartmentDtos = new List<DepartmentDto>();
             * ListDonation NewInfo = new ListDonation();
             */
            //Infomation to be exposed
            foreach (var info in AllInfos)
            {
                ListDonation NewInfo = new ListDonation
                {
                    DonationId       = info.DonationId,
                    AmountOfDonation = info.AmountOfDonation,
                    PaymentMethod    = info.PaymentMethod,
                    DonationDate     = info.DonationDate,
                    //Id = info.Id,
                    DepartmentId   = info.DepartmentId,
                    Id             = info.ApplicationUser.Id,
                    FirstName      = info.ApplicationUser.FirstName,
                    LastName       = info.ApplicationUser.LastName,
                    DepartmentName = info.Department.DepartmentName
                };

                /*
                 * DonationDto NewDonation = new DonationDto
                 * {
                 *  DonationId = info.DonationId,
                 *  AmountOfDonation = info.AmountOfDonation,
                 *  PaymentMethod = info.PaymentMethod,
                 *  DonationDate = info.DonationDate,
                 *  Id = info.Id,
                 *  DepartmentId = info.DepartmentId,
                 * };
                 *
                 * ApplicationUserDto NewUser = new ApplicationUserDto
                 * {
                 *  Id = info.ApplicationUser.Id,
                 *  FirstName = info.ApplicationUser.FirstName,
                 *  LastName = info.ApplicationUser.LastName
                 * };
                 *
                 * DepartmentDto NewDepartment = new DepartmentDto
                 * {
                 *  DepartmentId = info.Department.DepartmentId,
                 *  DepartmentName = info.Department.DepartmentName
                 * };
                 *
                 * DonationDtos.Add(NewDonation);
                 * UserDtos.Add(NewUser);
                 * DepartmentDtos.Add(NewDepartment);
                 */
                ModelView.Add(NewInfo);
            }

            /*
             * NewInfo.AllDonations = DonationDtos;
             * NewInfo.AllUsers = UserDtos;
             * NewInfo.AllDepartments = DepartmentDtos;
             */
            return(Ok(ModelView));
        }