Beispiel #1
0
        private static void CreateDonorInfoStreamLabels(HttpResponseMessage responseDonations)
        {
            DonorDataModel[] donorList =
                DonorDataModel.FromJson(responseDonations.Content.ReadAsStringAsync().Result);

            using (FileStream lastDonorData = new FileStream($"{_config.GetSection("ExtraLifeData").Get<ExtraLifeData>().StreamLabelOutputPath}//ExtraLifeMostRecentDonation.txt",
                                                             FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                if (donorList.Any())
                {
                    DonorDataModel mostRecentDataModel = donorList[0];
                    string         donation            = $"{GetDonorName(mostRecentDataModel)}{GetDonationAmount(mostRecentDataModel)}    "; //$"{donorName}{donationAmount}";
                    lastDonorData.SetLength(0);
                    lastDonorData.Write(new UTF8Encoding(true).GetBytes(donation), 0, donation.Length);
                    Console.WriteLine(donation);
                }
            }

            using (FileStream fullDonorListData = new FileStream(
                       $"{_config.GetSection("ExtraLifeData").Get<ExtraLifeData>().StreamLabelOutputPath}//ExtraLifeFullDonorList.txt",
                       FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                StringBuilder sb       = new StringBuilder();
                string        donation = string.Empty;
                fullDonorListData.SetLength(0);
                List <DonorDataModel> fullDonorList = donorList.ToList();
                foreach (var donor in fullDonorList)
                {
                    sb.Append($"{GetDonorName(donor)}{GetDonationAmount(donor)}    ");
                }

                string fullDonorData = sb.ToString();
                fullDonorListData.Write(new UTF8Encoding(true).GetBytes(fullDonorData), 0, fullDonorData.Length);
            }

            using (FileStream fullDonorListWithMessageData = new FileStream(
                       $"{_config.GetSection("ExtraLifeData").Get<ExtraLifeData>().StreamLabelOutputPath}//ExtraLifeFullDonorListWithMessages.txt",
                       FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                StringBuilder sb       = new StringBuilder();
                string        donation = string.Empty;
                fullDonorListWithMessageData.SetLength(0);
                List <DonorDataModel> fullDonorList = donorList.ToList();
                foreach (var donor in fullDonorList)
                {
                    sb.Append($"{GetDonorName(donor)}{GetDonationAmount(donor)}{GetDonationMessage(donor)}    ");
                }

                string fullDonorData = sb.ToString();
                fullDonorListWithMessageData.Write(new UTF8Encoding(true).GetBytes(fullDonorData), 0, fullDonorData.Length);
            }
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "cardNumber,expirationDate,ccv,amount,eventId,userId,fullName")] DonorDataModel donorDataModel, string eventId)
        {
            if (ModelState.IsValid)
            {
                int eventIdentification = 0;
                try
                {
                    eventIdentification = Int32.Parse(Request.Form["Events"].ToString());
                }
                catch (SystemException e)
                {
                }

                //changes all information into a model to go into the database
                donorDataModel.eventId  = eventIdentification;
                donorDataModel.fullName = User.Identity.Name;
                donorDataModel.userId   = User.Identity.GetUserId();
                db.DonorDataModels.Add(donorDataModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(donorDataModel));
        }
Beispiel #3
0
 private static string GetDonationMessage(DonorDataModel donorDataModel)
 {
     return(donorDataModel.Message == null ? string.Empty : $" Message: {donorDataModel.Message}");
 }
Beispiel #4
0
 private static string GetDonationAmount(DonorDataModel donorDataModel)
 {
     return(donorDataModel.Amount == null ? string.Empty : $": ${donorDataModel.Amount:N2}");
 }
Beispiel #5
0
 private static string GetDonorName(DonorDataModel donorDataModel)
 {
     return(donorDataModel.DisplayName ?? "Anonymous"); //Resources.AnonymousDonorName;
 }