// GET: ModifyDonation
        public ActionResult Index(string donationID)
        {
            Models.Donation     myModel = new Models.Donation();
            CodeFirst.CodeFirst db      = new CodeFirst.CodeFirst();
            if (donationID != null)
            {
                var intDonationID = Int32.Parse(donationID);
                var myDonation    = db.Donations.Where(i => i.DonationID == intDonationID).FirstOrDefault();

                myModel.DonationID = myDonation.DonationID;
                myModel.DateDate   = myDonation.DateDate;
                myModel.DonorPID   = myDonation.DonorPID;
                myModel.DonorOrgID = myDonation.DonorOrgID;

                myModel.DonorPeople = db.Donor_Person.AsEnumerable().Select(d => new SelectListItem
                {
                    Value = d.DonorPID.ToString(),
                    Text  = d.FirstName + " " + d.SecondName
                }).ToList();

                myModel.DonorOrgs = db.Donor_Org.AsEnumerable().Select(o => new SelectListItem
                {
                    Value = o.DonorOrgID.ToString(),
                    Text  = o.OrgName
                }).ToList();
                myModel.DonationTypes = db.Donation_Type.ToList();
                myModel.Lines         = myDonation.Donation_Line.ToList();
            }

            return(View(myModel));
        }
        public HttpResponseMessage Put(int id, Models.Donation donation)
        {
            if (ModelState.IsValid && id == donation.DonationID)
            {
                var updated = _donationRepository.UpdateDonation(donation);
                if (updated)
                {
                    return(Request.CreateResponse
                               (HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotModified, "Could not modify donation"));
                }
            }
            else
            {
                var errors     = ModelState.Select(x => x.Value.Errors).ToList();
                var errostring = new StringBuilder();
                foreach (var error in errors)
                {
                    var exMessage = error.Select(e => e.Exception.Message).ToList();
                    errostring.Append(exMessage);
                }

                return(Request.CreateErrorResponse(HttpStatusCode.NotModified, errostring.ToString()));
            }
        }
Пример #3
0
 // GET: Donation
 public ActionResult Index()
 {
     Models.Donation myModel = new Models.Donation();
     if (TempData["model"] != null)
     {
         myModel = (Models.Donation)TempData["model"];
         TempData.Remove("model");
     }
     return(View(myModel));
 }
Пример #4
0
        // GET: AddDonation
        public ActionResult Index()
        {
            var db    = new CodeFirst.CodeFirst();
            var model = new Models.Donation();

            model.DonorPeople = db.Donor_Person.AsEnumerable().Select(d => new SelectListItem
            {
                Value = d.DonorPID.ToString(),
                Text  = d.FirstName + " " + d.SecondName
            }).ToList();

            model.DonorOrgs = db.Donor_Org.AsEnumerable().Select(o => new SelectListItem
            {
                Value = o.DonorOrgID.ToString(),
                Text  = o.OrgName
            }).ToList();

            model.DonationTypes = db.Donation_Type.ToList();

            return(View(model));
        }
Пример #5
0
        // GET: DonationDetails
        public ActionResult Index(string donationID)
        {
            Models.Donation     myModel = new Models.Donation();
            CodeFirst.CodeFirst db      = new CodeFirst.CodeFirst();
            if (donationID != null)
            {
                var intID         = Int32.Parse(donationID);
                var myDonation    = db.Donations.Where(i => i.DonationID == intID).FirstOrDefault();
                var myDonorPerson = db.Donor_Person.Where(i => i.DonorPID == myDonation.DonorPID).FirstOrDefault();
                var myDonorOrg    = db.Donor_Org.Where(i => i.DonorOrgID == myDonation.DonorOrgID).FirstOrDefault();

                myModel.DonationID = myDonation.DonationID;
                myModel.DateDate   = myDonation.DateDate;
                myModel.DonorPID   = myDonation.DonorPID;
                myModel.DonorOrgID = myDonation.DonorOrgID;
                myModel.FirstName  = myDonorPerson != null ? myDonorPerson.FirstName : "";
                myModel.LastName   = myDonorPerson != null ? myDonorPerson.SecondName : "";
                myModel.OrgName    = myDonorOrg != null ? myDonorOrg.OrgName : "";
                myModel.Lines      = myDonation.Donation_Line.ToList();
            }

            return(View(myModel));
        }
        private void Add_InKind_Service(object sender, RoutedEventArgs e)
        {
            if (AMPM_Start.SelectedValue.ToString() == "PM" && Convert.ToInt32(BeginHour) != 12)
            {
                BeginHour = (Convert.ToInt32(BeginHour) + 12).ToString();
            }
            if (AMPM_End.SelectedValue.ToString() == "PM" && Convert.ToInt32(EndHour) != 12)
            {
                EndHour = (Convert.ToInt32(EndHour) + 12).ToString();
            }
            if (AMPM_Start.SelectedValue.ToString() == "AM" && Convert.ToInt32(BeginHour) == 12)
            {
                BeginHour = (Convert.ToInt32(BeginHour) - 12).ToString();
            }
            if (AMPM_End.SelectedValue.ToString() == "AM" && Convert.ToInt32(EndHour) == 12)
            {
                EndHour = (Convert.ToInt32(EndHour) - 12).ToString();
            }
            try
            {
                DateTime help = Convert.ToDateTime(DateRecieved.ToString());
                DateTime startDateTime = new DateTime(help.Year, help.Month, help.Day, Convert.ToInt32(BeginHour), Convert.ToInt32(BeginMinute), 0);
                DateTime endDateTime = new DateTime(help.Year, help.Month, help.Day, Convert.ToInt32(EndHour), Convert.ToInt32(EndMinute), 0);
                decimal timeDiff = (decimal)(endDateTime - startDateTime).TotalHours;
                if (ServiceDescription != null && ServiceDescription != "" && RatePerHour > 0 && timeDiff > 0 && Individual.SelectedIndex != -1)
                {
                    string[] separators = new string[] { ", " };
                    string Indiv = Individual.SelectedValue.ToString();
                    Models.FCS_DBModel db = new Models.FCS_DBModel();
                    //MessageBox.Show(ServiceDescription + "\n" + RatePerHour + "\n" + startDateTime + "\n" + endDateTime + "\n" + timeDiff + "\n" + Indiv);
                    string[] words = Indiv.Split(separators, StringSplitOptions.None);
                    string FName = words[0]; string LName = words[1]; string FNumber = words[2];
                    var donorID = (from dc in db.DonorContacts
                                   join d in db.Donors on dc.DonorID equals d.DonorID
                                   where dc.ContactFirstName == FName && dc.ContactLastName == LName && dc.ContactPhone == FNumber
                                   && (d.DonorType == "Individual" || d.DonorType == "Anonymous")
                                   select dc.DonorID).Distinct().FirstOrDefault();

                    if (IsEvent)
                    {
                        Models.Donation donation = new Models.Donation();

                        donation.DonorID = donorID;
                        donation.Restricted = false;
                        donation.InKind = true;
                        donation.DonationAmount = 0M;
                        donation.DonationDate = Convert.ToDateTime(DateRecieved.ToString());
                        donation.EventID = EventID;

                        db.Donations.Add(donation);
                        db.SaveChanges();

                        Models.In_Kind_Service inKind = new Models.In_Kind_Service();

                        inKind.DonationID = donation.DonationID;
                        inKind.StartDateTime = startDateTime;
                        inKind.EndDateTime = endDateTime;
                        inKind.RatePerHour = RatePerHour;
                        inKind.ServiceDescription = ServiceDescription;
                        inKind.ServiceLength = (double)timeDiff;
                        inKind.ServiceValue = RatePerHour * timeDiff;

                        db.In_Kind_Service.Add(inKind);
                        db.SaveChanges();
                    }
                    else
                    {
                        Models.Donation donation = new Models.Donation();

                        donation.DonorID = donorID;
                        donation.InKind = false;
                        donation.Restricted = true;
                        donation.DonationAmount = 0M;
                        donation.DonationDate = Convert.ToDateTime(DateRecieved.ToString());

                        db.Donations.Add(donation);
                        db.SaveChanges();

                        Models.In_Kind_Service inKind = new Models.In_Kind_Service();

                        inKind.DonationID = donation.DonationID;
                        inKind.StartDateTime = startDateTime;
                        inKind.EndDateTime = endDateTime;
                        inKind.RatePerHour = RatePerHour;
                        inKind.ServiceDescription = ServiceDescription;
                        inKind.ServiceLength = (double)timeDiff;
                        inKind.ServiceValue = RatePerHour * timeDiff;

                        db.In_Kind_Service.Add(inKind);
                        db.SaveChanges();
                    }

                    this.Close();
                }
                else
                {
                    MessageBox.Show("Please check the data entered.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please check the data entered.");
            }
        }
        private void Add_InKind_Service(object sender, RoutedEventArgs e)
        {
            if (AMPM_Start.SelectedValue.ToString() == "PM" && Convert.ToInt32(BeginHour) != 12)
            {
                BeginHour = (Convert.ToInt32(BeginHour) + 12).ToString();
            }
            if (AMPM_End.SelectedValue.ToString() == "PM" && Convert.ToInt32(EndHour) != 12)
            {
                EndHour = (Convert.ToInt32(EndHour) + 12).ToString();
            }
            if (AMPM_Start.SelectedValue.ToString() == "AM" && Convert.ToInt32(BeginHour) == 12)
            {
                BeginHour = (Convert.ToInt32(BeginHour) - 12).ToString();
            }
            if (AMPM_End.SelectedValue.ToString() == "AM" && Convert.ToInt32(EndHour) == 12)
            {
                EndHour = (Convert.ToInt32(EndHour) - 12).ToString();
            }
            try
            {
                DateTime help          = Convert.ToDateTime(DateRecieved.ToString());
                DateTime startDateTime = new DateTime(help.Year, help.Month, help.Day, Convert.ToInt32(BeginHour), Convert.ToInt32(BeginMinute), 0);
                DateTime endDateTime   = new DateTime(help.Year, help.Month, help.Day, Convert.ToInt32(EndHour), Convert.ToInt32(EndMinute), 0);
                decimal  timeDiff      = (decimal)(endDateTime - startDateTime).TotalHours;
                if (ServiceDescription != null && ServiceDescription != "" && RatePerHour > 0 && timeDiff > 0 && Individual.SelectedIndex != -1)
                {
                    string[]           separators = new string[] { ", " };
                    string             Indiv      = Individual.SelectedValue.ToString();
                    Models.FCS_DBModel db         = new Models.FCS_DBModel();
                    //MessageBox.Show(ServiceDescription + "\n" + RatePerHour + "\n" + startDateTime + "\n" + endDateTime + "\n" + timeDiff + "\n" + Indiv);
                    string[] words = Indiv.Split(separators, StringSplitOptions.None);
                    string   FName = words[0]; string LName = words[1]; string FNumber = words[2];
                    var      donorID = (from dc in db.DonorContacts
                                        join d in db.Donors on dc.DonorID equals d.DonorID
                                        where dc.ContactFirstName == FName && dc.ContactLastName == LName && dc.ContactPhone == FNumber &&
                                        (d.DonorType == "Individual" || d.DonorType == "Anonymous")
                                        select dc.DonorID).Distinct().FirstOrDefault();

                    if (IsEvent)
                    {
                        Models.Donation donation = new Models.Donation();

                        donation.DonorID        = donorID;
                        donation.Restricted     = false;
                        donation.InKind         = true;
                        donation.DonationAmount = 0M;
                        donation.DonationDate   = Convert.ToDateTime(DateRecieved.ToString());
                        donation.EventID        = EventID;

                        db.Donations.Add(donation);
                        db.SaveChanges();

                        Models.In_Kind_Service inKind = new Models.In_Kind_Service();

                        inKind.DonationID         = donation.DonationID;
                        inKind.StartDateTime      = startDateTime;
                        inKind.EndDateTime        = endDateTime;
                        inKind.RatePerHour        = RatePerHour;
                        inKind.ServiceDescription = ServiceDescription;
                        inKind.ServiceLength      = (double)timeDiff;
                        inKind.ServiceValue       = RatePerHour * timeDiff;

                        db.In_Kind_Service.Add(inKind);
                        db.SaveChanges();
                    }
                    else
                    {
                        Models.Donation donation = new Models.Donation();

                        donation.DonorID        = donorID;
                        donation.InKind         = false;
                        donation.Restricted     = true;
                        donation.DonationAmount = 0M;
                        donation.DonationDate   = Convert.ToDateTime(DateRecieved.ToString());

                        db.Donations.Add(donation);
                        db.SaveChanges();

                        Models.In_Kind_Service inKind = new Models.In_Kind_Service();

                        inKind.DonationID         = donation.DonationID;
                        inKind.StartDateTime      = startDateTime;
                        inKind.EndDateTime        = endDateTime;
                        inKind.RatePerHour        = RatePerHour;
                        inKind.ServiceDescription = ServiceDescription;
                        inKind.ServiceLength      = (double)timeDiff;
                        inKind.ServiceValue       = RatePerHour * timeDiff;

                        db.In_Kind_Service.Add(inKind);
                        db.SaveChanges();
                    }

                    this.Close();
                }
                else
                {
                    MessageBox.Show("Please check the data entered.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please check the data entered.");
            }
        }
Пример #8
0
        private void Add_InKind_Item(object sender, RoutedEventArgs e)
        {
            if (ItemName != null && ItemName != "" && ItemDescription != null && ItemDescription != "" && DateRecieved.ToString() != null && DateRecieved.ToString() != "")
            {
                Models.FCS_DBModel db = new Models.FCS_DBModel();
                //Then its an organization
                if (OrgOrIndividual.IsChecked.Value && Organization.SelectedIndex != -1)
                {
                    string Organiz = Organization.SelectedValue.ToString();
                    //MessageBox.Show(ItemName + "\n" + ItemDescription + "\n" + DateRecieved + "\n" + Organiz + "\n" + "You got HERE");
                    var donorID = (from d in db.Donors
                                   where d.OrganizationName == Organiz
                                   select d.DonorID).Distinct().First();
                    //MessageBox.Show(donorID.ToString());

                    if (IsEvent)
                    {
                        Models.Donation donation = new Models.Donation();
                        donation.DonorID        = donorID;
                        donation.Restricted     = false;
                        donation.InKind         = true;
                        donation.DonationAmount = 0M;
                        donation.DonationDate   = Convert.ToDateTime(DateRecieved.ToString());
                        donation.EventID        = EventID;
                        db.Donations.Add(donation);
                        db.SaveChanges();

                        Models.In_Kind_Item inKind = new Models.In_Kind_Item();
                        inKind.DonationID      = donation.DonationID;
                        inKind.ItemName        = ItemName;
                        inKind.ItemDescription = ItemDescription;
                        db.In_Kind_Item.Add(inKind);
                        db.SaveChanges();
                    }
                    else
                    {
                        Models.Donation donation = new Models.Donation();
                        donation.DonorID        = donorID;
                        donation.Restricted     = false;
                        donation.InKind         = true;
                        donation.DonationAmount = 0M;
                        donation.DonationDate   = Convert.ToDateTime(DateRecieved.ToString());
                        db.Donations.Add(donation);
                        db.SaveChanges();

                        Models.In_Kind_Item inKind = new Models.In_Kind_Item();
                        inKind.DonationID      = donation.DonationID;
                        inKind.ItemName        = ItemName;
                        inKind.ItemDescription = ItemDescription;
                        db.In_Kind_Item.Add(inKind);
                        db.SaveChanges();
                    }
                }
                //then its an individual
                else if (Individual.SelectedIndex != -1)
                {
                    string[] separators = new string[] { ", " };
                    string   Indiv      = Individual.SelectedValue.ToString();
                    //MessageBox.Show(ItemName + "\n" + ItemDescription + "\n" + DateRecieved + "\n" + Indiv);
                    string[] words = Indiv.Split(separators, StringSplitOptions.None);
                    string   FName = words[0]; string LName = words[1]; string FNumber = words[2];
                    var      donorID = (from dc in db.DonorContacts
                                        join d in db.Donors on dc.DonorID equals d.DonorID
                                        where dc.ContactFirstName == FName && dc.ContactLastName == LName && dc.ContactPhone == FNumber &&
                                        (d.DonorType == "Individual" || d.DonorType == "Anonymous")
                                        select dc.DonorID).Distinct().FirstOrDefault();

                    if (IsEvent)
                    {
                        Models.Donation donation = new Models.Donation();
                        donation.DonorID        = donorID;
                        donation.Restricted     = false;
                        donation.InKind         = true;
                        donation.DonationAmount = 0M;
                        donation.DonationDate   = Convert.ToDateTime(DateRecieved.ToString());
                        donation.EventID        = EventID;
                        db.Donations.Add(donation);
                        db.SaveChanges();

                        Models.In_Kind_Item inKind = new Models.In_Kind_Item();
                        inKind.DonationID      = donation.DonationID;
                        inKind.ItemName        = ItemName;
                        inKind.ItemDescription = ItemDescription;
                        db.In_Kind_Item.Add(inKind);
                        db.SaveChanges();
                    }
                    else
                    {
                        Models.Donation donation = new Models.Donation();
                        donation.DonorID        = donorID;
                        donation.Restricted     = false;
                        donation.InKind         = true;
                        donation.DonationAmount = 0M;
                        donation.DonationDate   = Convert.ToDateTime(DateRecieved.ToString());
                        db.Donations.Add(donation);
                        db.SaveChanges();

                        Models.In_Kind_Item inKind = new Models.In_Kind_Item();
                        inKind.DonationID      = donation.DonationID;
                        inKind.ItemName        = ItemName;
                        inKind.ItemDescription = ItemDescription;
                        db.In_Kind_Item.Add(inKind);
                        db.SaveChanges();
                    }
                }
                else
                {
                    MessageBox.Show("Make sure to select an organization or an individual");
                    return;
                }

                this.Close();
            }
            //add both patient and household
            else
            {
                MessageBox.Show("Make sure the data is correct.");
            }
        }
        private void Add_InKind_Item(object sender, RoutedEventArgs e)
        {
            if (ItemName != null && ItemName != "" && ItemDescription != null && ItemDescription != "" && DateRecieved.ToString() != null && DateRecieved.ToString() != "")
            {
                Models.FCS_DBModel db = new Models.FCS_DBModel();
                //Then its an organization
                if (OrgOrIndividual.IsChecked.Value && Organization.SelectedIndex != -1)
                {
                    string Organiz = Organization.SelectedValue.ToString();
                    //MessageBox.Show(ItemName + "\n" + ItemDescription + "\n" + DateRecieved + "\n" + Organiz + "\n" + "You got HERE");
                    var donorID = (from d in db.Donors
                                   where d.OrganizationName == Organiz
                                   select d.DonorID).Distinct().First();
                    //MessageBox.Show(donorID.ToString());

                    if (IsEvent)
                    {
                        Models.Donation donation = new Models.Donation();
                        donation.DonorID = donorID;
                        donation.Restricted = false;
                        donation.InKind = true;
                        donation.DonationAmount = 0M;
                        donation.DonationDate = Convert.ToDateTime(DateRecieved.ToString());
                        donation.EventID = EventID;
                        db.Donations.Add(donation);
                        db.SaveChanges();

                        Models.In_Kind_Item inKind = new Models.In_Kind_Item();
                        inKind.DonationID = donation.DonationID;
                        inKind.ItemName = ItemName;
                        inKind.ItemDescription = ItemDescription;
                        db.In_Kind_Item.Add(inKind);
                        db.SaveChanges();
                    }
                    else
                    {
                        
                        Models.Donation donation = new Models.Donation();
                        donation.DonorID = donorID;
                        donation.Restricted = false;
                        donation.InKind = true;
                        donation.DonationAmount = 0M;
                        donation.DonationDate = Convert.ToDateTime(DateRecieved.ToString());
                        db.Donations.Add(donation);
                        db.SaveChanges();

                        Models.In_Kind_Item inKind = new Models.In_Kind_Item();
                        inKind.DonationID = donation.DonationID;
                        inKind.ItemName = ItemName;
                        inKind.ItemDescription = ItemDescription;
                        db.In_Kind_Item.Add(inKind);
                        db.SaveChanges();
                    }
                }
                //then its an individual
                else if (Individual.SelectedIndex != -1)
                {
                    string[] separators = new string[] { ", " };
                    string Indiv = Individual.SelectedValue.ToString();
                    //MessageBox.Show(ItemName + "\n" + ItemDescription + "\n" + DateRecieved + "\n" + Indiv);
                    string[] words = Indiv.Split(separators, StringSplitOptions.None);
                    string FName = words[0]; string LName = words[1]; string FNumber = words[2];
                    var donorID = (from dc in db.DonorContacts
                                   join d in db.Donors on dc.DonorID equals d.DonorID
                                   where dc.ContactFirstName == FName && dc.ContactLastName == LName && dc.ContactPhone == FNumber
                                   && (d.DonorType == "Individual" || d.DonorType == "Anonymous")
                                   select dc.DonorID).Distinct().FirstOrDefault();

                    if (IsEvent)
                    {
                        Models.Donation donation = new Models.Donation();
                        donation.DonorID = donorID;
                        donation.Restricted = false;
                        donation.InKind = true;
                        donation.DonationAmount = 0M;
                        donation.DonationDate = Convert.ToDateTime(DateRecieved.ToString());
                        donation.EventID = EventID;
                        db.Donations.Add(donation);
                        db.SaveChanges();

                        Models.In_Kind_Item inKind = new Models.In_Kind_Item();
                        inKind.DonationID = donation.DonationID;
                        inKind.ItemName = ItemName;
                        inKind.ItemDescription = ItemDescription;
                        db.In_Kind_Item.Add(inKind);
                        db.SaveChanges();
                    }
                    else
                    {
                        Models.Donation donation = new Models.Donation();
                        donation.DonorID = donorID;
                        donation.Restricted = false;
                        donation.InKind = true;
                        donation.DonationAmount = 0M;
                        donation.DonationDate = Convert.ToDateTime(DateRecieved.ToString());
                        db.Donations.Add(donation);
                        db.SaveChanges();

                        Models.In_Kind_Item inKind = new Models.In_Kind_Item();
                        inKind.DonationID = donation.DonationID;
                        inKind.ItemName = ItemName;
                        inKind.ItemDescription = ItemDescription;
                        db.In_Kind_Item.Add(inKind);
                        db.SaveChanges();
                    }
                }
                else
                {
                    MessageBox.Show("Make sure to select an organization or an individual");
                    return;
                }
                
                this.Close();

            }
            //add both patient and household
            else
            {
                MessageBox.Show("Make sure the data is correct.");
            }
        }
        //[ValidateRecaptcha]
        public async Task <IActionResult> Donate(DonationViewModel model)
        {
            if (string.IsNullOrEmpty(model.BrainTreePayment.Nonce))
            {
                ModelState.AddModelError("", "incomplete payment information provided");
            }
            else
            {
                try
                {
                    // get model state errors
                    var errors = ModelState.Values.SelectMany(v => v.Errors);

                    // if paying with a credit card the fields for credit card number/cvs/month/year will be invalid because we do not send them to the server
                    // so count the errors on the field validation that do not start with 'card ' (comes from the property attributes in the model class Apply.cs)
                    // TODO validate if this is still needed - all card validation has been removed b/c client side validation requires 'name' properties
                    //      which have been removed for PCI compliance.
                    var errorCount = errors.Count(m => !m.ErrorMessage.StartsWith("card "));
                    var result     = new ServiceResult();
                    if (errorCount == 0)
                    {
                        #region Process Payment
                        var paymentMethod = (PaymentTypeEnum)Enum.Parse(typeof(PaymentTypeEnum), model.BrainTreePayment.PaymentMethod);
                        var phone         = model.DonorPhoneNumber;
                        var paymentResult = new ServiceResult();

                        var paymentRequestResult = new ServiceResult();

                        if (paymentMethod == PaymentTypeEnum.Paypal)
                        {
                            paymentResult = _paymentService.SendPayment(model.AmountDonation,
                                                                        model.BrainTreePayment.Nonce,
                                                                        true,
                                                                        paymentMethod,
                                                                        model.BrainTreePayment.DeviceData,
                                                                        "donation",
                                                                        model.Comments,
                                                                        model.BrainTreePayment.PayeeFirstName,
                                                                        model.BrainTreePayment.PayeeLastName,
                                                                        phone,
                                                                        model.DonorEmail);
                        }
                        else
                        {
                            var stateCode = _context.States.First(p => p.Id == model.BrainTreePayment.PayeeAddressStateId).Code;

                            paymentRequestResult = _paymentService.SendPayment(model.AmountDonation,
                                                                               model.BrainTreePayment.Nonce,
                                                                               true,
                                                                               paymentMethod,
                                                                               model.BrainTreePayment.DeviceData,
                                                                               "donation",
                                                                               model.Comments,
                                                                               model.BrainTreePayment.PayeeFirstName,
                                                                               model.BrainTreePayment.PayeeLastName,
                                                                               model.BrainTreePayment.PayeeAddressStreet1,
                                                                               model.BrainTreePayment.PayeeAddressStreet2,
                                                                               model.BrainTreePayment.PayeeAddressCity,
                                                                               stateCode,
                                                                               model.BrainTreePayment.PayeeAddressPostalCode,
                                                                               "US",
                                                                               phone,
                                                                               model.DonorEmail);
                        }

                        if (!paymentRequestResult.IsSuccess)
                        {
                            // TODO: handle failure to pay
                            result.IsSuccess = false;
                            result.Messages.Add("Payment Failure - see below for details: ");
                            result.Messages.AddRange(paymentRequestResult.Messages);

                            _logger.LogError("Donation Payment Failed {@DonationPaymentErrors}", result.Messages);
                            ModelState.AddModelError("", "Unable to process your payment. Try again, and if the problem persists see your system administrator.");
                            foreach (var error in paymentRequestResult.Messages)
                            {
                                ModelState.AddModelError("", error);
                            }

                            RedirectToAction("Index");
                        }

                        // payment is a success. capture the transaction id from braintree
                        model.BrainTreePayment.BraintreeTransactionId = paymentRequestResult.NewKey;
                        #endregion

                        #region Database

                        var donationId = Guid.NewGuid();
                        var personId   = Guid.NewGuid();

                        #region Copy ViewModel to database Model
                        var dbDonation = new Models.Donation
                        {
                            Id                 = donationId,
                            Amount             = model.AmountDonation,
                            DonorNote          = model.Comments,
                            DateTimeOfDonation = DateTime.Now,
                            PersonId           = personId,
                            PaymentType        = paymentMethod.ToString()
                        };

                        var dbPerson = new Models.Person
                        {
                            Id = personId,
                            CreatedTimestamp = DateTime.Today,
                            FirstName        = model.BrainTreePayment.PayeeFirstName,
                            LastName         = model.BrainTreePayment.PayeeLastName,
                            IsActive         = true,
                            IsDonor          = true,
                            FullName         = model.BrainTreePayment.PayeeFullName,
                            CanEmail         = model.IsEmailable.HasValue ? model.IsEmailable.Value : false
                        };

                        if (paymentMethod == PaymentTypeEnum.CreditCard)
                        {
                            dbPerson.Addresses = new List <Models.Address> {
                                new Models.Address
                                {
                                    Id               = Guid.NewGuid(),
                                    PersonId         = personId,
                                    Address1         = model.BrainTreePayment.PayeeAddressStreet1,
                                    Address2         = model.BrainTreePayment.PayeeAddressStreet2,
                                    StatesId         = model.BrainTreePayment.PayeeAddressStateId.Value,
                                    AddressTypeId    = 1, //Primary
                                    City             = model.BrainTreePayment.PayeeAddressCity,
                                    IsBillingAddress = true,
                                    ZipCode          = model.BrainTreePayment.PayeeAddressPostalCode
                                }
                            };
                        }

                        if (!string.IsNullOrEmpty(model.DonorEmail))
                        {
                            dbPerson.Emails = new List <Models.Email>
                            {
                                new Models.Email
                                {
                                    Id          = Guid.NewGuid(),
                                    PersonId    = personId,
                                    Address     = model.DonorEmail,
                                    EmailTypeId = 0
                                }
                            };
                        }

                        if (!string.IsNullOrEmpty(model.DonorPhoneNumber))
                        {
                            dbPerson.Phones = new List <Models.Phone>
                            {
                                new Models.Phone
                                {
                                    Id          = Guid.NewGuid(),
                                    PersonId    = personId,
                                    Number      = model.DonorPhoneNumber,
                                    PhoneTypeId = 1
                                }
                            };
                        }
                        #endregion

                        #region Add to Database
                        _context.Add(dbDonation);
                        _context.Add(dbPerson);
                        #endregion

                        #region Save to Database and check exceptions
                        try
                        {
                            _logger.LogInformation("Saving donation information to database: {@dbDonation}", dbDonation);
                            var numChanges = _context.SaveChanges();
                            if (numChanges > 0)
                            {
                                result.IsSuccess = true;
                            }
                        }
                        catch (DbUpdateException ex)
                        {
                            _logger.LogError(new EventId(7), ex, "Database Update Exception saving donation information");
                        }
                        catch (InvalidOperationException ex)
                        {
                            _logger.LogError(new EventId(7), ex, "Invalid Operation Exception saving donation information");
                        }
                        #endregion

                        #endregion

                        #region Send Emails
                        var groupEmail = _systemServices.GetSetting("Email-Contact").Value;

                        var subject  = string.Format("[TXHR Web] [Donation] [Amount=${0}] - {1}", model.AmountDonation, model.BrainTreePayment.PayeeFullName);
                        var bodyText = string.Format(@"
Thank you, {0}. Your donation of {1} is greatly appreciated. For your records:
Payment method: {2}
Payment Date: {3}
Payment Confirmation Id: {4}

Thanks again,
Texas Husky Rescue
1-877-TX-HUSKY (894-8759)(phone / fax)
PO Box 118891, Carrollton, TX 75007",
                                                     model.BrainTreePayment.PayeeFullName, model.AmountDonation, paymentMethod, DateTime.Now.Date, model.BrainTreePayment.BraintreeTransactionId);


                        var emailAppResult = await _emailService.SendEmailAsync(model.DonorEmail, groupEmail, groupEmail, subject, bodyText, "donation");

                        bodyText = string.Format(@"
Donor Name: {0}
Donor Email: {1}
Donor Phone: {2}
Donation Amount: {3}
Payment method: {4}
Payment Date: {5}
Payment Confirmation Id: {6}
Comments : {7}",
                                                 model.BrainTreePayment.PayeeFullName, model.DonorEmail, model.DonorPhoneNumber, model.AmountDonation, paymentMethod, DateTime.Now.Date, model.BrainTreePayment.BraintreeTransactionId, model.Comments);

                        var emailGroupResult = await _emailService.SendEmailAsync(groupEmail, groupEmail, groupEmail, subject, bodyText, "donation");

                        #endregion

                        if (result.IsSuccess)
                        {
                            return(RedirectToAction("ThankYou"));
                        }
                        else
                        {
                            foreach (var error in result.Messages)
                            {
                                ModelState.AddModelError(error.GetHashCode().ToString(), error);
                                _logger.LogError("Data Exception saving Donation {@modelGolfReg}", model);
                            }

                            return(RedirectToAction("ThankYou"));
                        }
                    }
                    _logger.LogInformation("Donation Model Errors {@errors} {@modelDonation}", result.Messages, model);
                }
                catch (Exception dex)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
                    _logger.LogError(new EventId(6), dex, "Data Exception saving Donation {@modelDonation}", model);
                }
            }
            return(RedirectToAction("Index"));
        }