//Aka save/update charity
        public void EditCharity(Charity charity)
        {
            var db = new ApplicationDbContext();
            if (charity.CharityId == 0)
            {
                //first add any children
                //Add new user
                db.Charities.Add(charity);
            }
            else
            {
                Charity dbEntry = db.Charities.Find(charity.CharityId);
                if (dbEntry != null)
                {
                    //dbEntry = charity;  this works too, no change in the db data as far as I can tell

                    dbEntry.Name = charity.Name;
                    dbEntry.Address = charity.Address;
                    dbEntry.City = charity.City;
                    dbEntry.Zip = charity.Zip;
                    dbEntry.Phone = charity.Phone;
                    dbEntry.FederalTaxId = charity.FederalTaxId;
                    dbEntry.TypeOfCharity = charity.TypeOfCharity;
                }
            }
            db.SaveChanges();
        }
        public void UpdateForm(Entities.Form form)
        {
            var db = new ApplicationDbContext();

               if (form.FormId == 0)
               {
               db.Forms.Add(form);
               }
               else
               {
               var dbEntry = db.Forms.Find(form.FormId);
               if (dbEntry != null)
               {
                   dbEntry = form;

                   //dbEntry.ActualSalesFour = form.ActualSalesFour;
                   //dbEntry.ActualSalesFive = form.ActualSalesFive;
                   //dbEntry.ActualSalesSix = form.ActualSalesSix;
                   //dbEntry.ActualSalesSeven = form.ActualSalesSeven;
                   //dbEntry.ActualSalesEight = form.ActualSalesEight;
                   //dbEntry.ActualGcFour = form.ActualGcFour;
                   //dbEntry.ActualGcFive = form.ActualGcFive;
                   //dbEntry.ActualGcSix = form.ActualGcSix;
                   //dbEntry.ActualGcSeven = form.ActualGcSeven;
                   //dbEntry.ActualGcEight = form.ActualGcEight;
                   //dbEntry.PosiDonations = form.PosiDonations;
                   //dbEntry.Notes = form.Notes;
               }
               }

               db.SaveChanges();
        }
 public void AddPartnershipNight(PartnershipNight pn)
 {
     //throw new NotImplementedException();
     var db = new ApplicationDbContext();
     db.PartnershipNights.Add(pn);
     db.SaveChanges();
     //TODO: Add in error handling
 }
 public Form DeleteForm(int id)
 {
     var db = new ApplicationDbContext();
     var dbEntry = db.Forms.Find(id);
     if (dbEntry != null)
     {
         db.Forms.Remove(dbEntry);
         db.SaveChanges();
     }
     return dbEntry;
 }
 //If we decide not to allow deletion we can take this out later
 public Charity DeleteCharity(int charityId)
 {
     var db = new ApplicationDbContext();
     Charity dbEntry = db.Charities.Find(charityId);
     if (dbEntry != null)
     {
         db.Charities.Remove(dbEntry);
         db.SaveChanges();
     }
     return dbEntry;
 }
 public BvLocation DeleteBvLocation(int bvLocationId)
 {
     var db = new ApplicationDbContext();
     BvLocation dbEntry = db.BvLocations.Find(bvLocationId);
     if (dbEntry != null)
     {
         db.BvLocations.Remove(dbEntry);
         db.SaveChanges();
     }
     return dbEntry;
 }
 //should this take a partnership night or id as parameter?
 public PartnershipNight DeletePartnershipNight(int id)
 {
     //throw new NotImplementedException();
     var db = new ApplicationDbContext();
     PartnershipNight dbEntry = db.PartnershipNights.Find(id);
     if (dbEntry != null)
     {
         db.PartnershipNights.Remove(dbEntry);
         db.SaveChanges();
     }
     return dbEntry;
     //TODO: Add in error handling
 }
 //TODO:  need use event props to create pnight props and save that to db
 public bool CreateNewEvent(string Title, int id ,string NewStartDate, string NewStartTime, string NewEndDt, string NewEndTime)
 {
     try
     {
         var db = new ApplicationDbContext();
         PartnershipNight rec = new PartnershipNight();
         rec.Charity = db.Charities.Find(Title);
         rec.BVLocation = db.BvLocations.Find(id);
         rec.StartDate = DateTime.ParseExact(NewStartDate + " " + NewStartTime, "MM/dd/yyyy HH:mm tt", CultureInfo.InvariantCulture);
         rec.EndDate = DateTime.ParseExact(NewEndDt + " " + NewEndTime, "MM/dd/yyyy H:mm tt", CultureInfo.InvariantCulture);
         db.PartnershipNights.Add(rec);
         db.SaveChanges();
     }
     catch (Exception)
     {
         return false;
     }
     return true;
 }
        public void SaveBvLocation(BvLocation l)
        {
            var db = new ApplicationDbContext();
            if (l.BvLocationId == 0)
                db.BvLocations.Add(l);
            else
            {
                BvLocation dbEntry = db.BvLocations.Find(l.BvLocationId);
                if (dbEntry != null)
                {
                    dbEntry.Address = l.Address;
                    dbEntry.BvStoreNum = l.BvStoreNum;
                    dbEntry.City = l.City;
                    dbEntry.Phone = l.Phone;
                    dbEntry.Zip = l.Zip;
                }

            }
            db.SaveChanges();
        }
        public ActionResult UserDelete(string id = null)
        {
            var Db = new ApplicationDbContext();

            ApplicationUser deletedUser = Db.Users.First(u => u.Id == id);

            if (deletedUser != null)
            {
                Db.Users.Remove(deletedUser);
                Db.SaveChanges();
                TempData["message"] = string.Format("{0} was deleted", deletedUser.UserName);
            }

            return RedirectToAction("UserIndex");
        }
        public void UpdateForm(Entities.Form form)
        {
            var db = new ApplicationDbContext();

               if (form.FormId == 0)
               {
               db.Forms.Add(form);
               }
               else
               {
               var dbEntry = db.Forms.Find(form.FormId);
               if (dbEntry != null)
               {
                   dbEntry.FormId = form.FormId;
                   dbEntry.ActualAverageCheck_45 = form.ActualAverageCheck_45;
                   dbEntry.ActualAverageCheck_56 = form.ActualAverageCheck_56;
                   dbEntry.ActualAverageCheck_67 = form.ActualAverageCheck_67;
                   dbEntry.ActualAverageCheck_78 = form.ActualAverageCheck_78;
                   dbEntry.ActualAverageCheck_89 = form.ActualAverageCheck_89;
                   dbEntry.ActualAverageCheckTotal = form.ActualAverageCheckTotal;
                   dbEntry.ActualGuestCount_45 = form.ActualGuestCount_45;
                   dbEntry.ActualGuestCount_56 = form.ActualGuestCount_56;
                   dbEntry.ActualGuestCount_67 = form.ActualGuestCount_67;
                   dbEntry.ActualGuestCount_78 = form.ActualGuestCount_78;
                   dbEntry.ActualGuestCount_89 = form.ActualGuestCount_89;
                   dbEntry.ActualGuestCountTotal = form.ActualGuestCountTotal;
                   dbEntry.ActualSales_45 = form.ActualSales_45;
                   dbEntry.ActualSales_56 = form.ActualSales_56;
                   dbEntry.ActualSales_67 = form.ActualSales_67;
                   dbEntry.ActualSales_78 = form.ActualSales_78;
                   dbEntry.ActualSales_89 = form.ActualSales_89;
                   dbEntry.ActualSalesTotal = form.ActualSalesTotal;
                   dbEntry.Average_45_GuestCount = form.Average_45_GuestCount;
                   dbEntry.Average_45_Sales = form.Average_45_Sales;
                   dbEntry.Average_56_GuestCount = form.Average_56_GuestCount;
                   dbEntry.Average_56_Sales = form.Average_56_Sales;
                   dbEntry.Average_67_GuestCount = form.Average_67_GuestCount;
                   dbEntry.Average_67_Sales = form.Average_67_Sales;
                   dbEntry.Average_78_GuestCount = form.Average_78_GuestCount;
                   dbEntry.Average_78_Sales = form.Average_78_Sales;
                   dbEntry.Average_89_GuestCount = form.Average_89_GuestCount;
                   dbEntry.Average_89_Sales = form.Average_89_Sales;
                   dbEntry.Average_GuestCountTotal = form.Average_GuestCountTotal;
                   dbEntry.Average_SalesTotal = form.Average_SalesTotal;
                   dbEntry.ContactName = form.ContactName;
                   dbEntry.DateOfPartnership = form.DateOfPartnership;
                   dbEntry.Donations10PercentOfSalesToGL7700 = form.Donations10PercentOfSalesToGL7700;
                   dbEntry.DonationsTakenOnThePosiRegisterCodeToGL2005 = form.DonationsTakenOnThePosiRegisterCodeToGL2005;
                   dbEntry.FederalTaxID = form.FederalTaxID;
                   dbEntry.GLCode2005 = form.GLCode2005;
                   dbEntry.GLCode7700 = form.GLCode7700;
                   dbEntry.GuestCountContribution_3WeekAverage = form.GuestCountContribution_3WeekAverage;
                   dbEntry.GuestCountContribution_ActualNumber = form.GuestCountContribution_ActualNumber;
                   dbEntry.GuestCountContribution_GCCountribution = form.GuestCountContribution_GCCountribution;
                   dbEntry.HostingRestaurant = form.HostingRestaurant;
                   dbEntry.IsComplete = form.IsComplete;
                   dbEntry.LastWeekAverageCheck_45 = form.LastWeekAverageCheck_45;
                   dbEntry.LastWeekAverageCheck_56 = form.LastWeekAverageCheck_56;
                   dbEntry.LastWeekAverageCheck_67 = form.LastWeekAverageCheck_67;
                   dbEntry.LastWeekAverageCheck_78 = form.LastWeekAverageCheck_78;
                   dbEntry.LastWeekAverageCheck_89 = form.LastWeekAverageCheck_89;
                   dbEntry.LastWeekAverageCheckTotal = form.LastWeekAverageCheckTotal;
                   dbEntry.MailPartnershipCheckToBV = form.MailPartnershipCheckToBV;
                   dbEntry.NameOnCheck = form.NameOnCheck;
                   dbEntry.NewPartner = form.NewPartner;
                   dbEntry.Notes = form.Notes;
                   dbEntry.OrganizationMailingAddress = form.OrganizationMailingAddress;
                   dbEntry.OrganizationMailingCity = form.OrganizationMailingCity;
                   dbEntry.OrganizationMailingState = form.OrganizationMailingState;
                   dbEntry.OrganizationMailingZip = form.OrganizationMailingZip;
                   dbEntry.OrganizationPhone = form.OrganizationPhone;
                   dbEntry.PosiDonations = form.PosiDonations;
                   dbEntry.Purpose = form.Purpose;
                   dbEntry.SalesContribution_3WeekAverage = form.SalesContribution_3WeekAverage;
                   dbEntry.SalesContribution_Actual = form.SalesContribution_Actual;
                   dbEntry.SalesContribution_Difference = form.SalesContribution_Difference;
                   dbEntry.SalesContribution_Donation = form.SalesContribution_Donation;
                   dbEntry.SalesContribution_SalesContribution = form.SalesContribution_SalesContribution;
                   dbEntry.Scenario1_EstimatedDonation = form.Scenario1_EstimatedDonation;
                   dbEntry.Scenario1_EstimatedGuestCount = form.Scenario1_EstimatedGuestCount;
                   dbEntry.Scenario1_GuestCountInvited = form.Scenario1_GuestCountInvited;
                   dbEntry.Scenario1_TargetedGuestCount = form.Scenario1_TargetedGuestCount;
                   dbEntry.Scenario1_ThreeWeekAverageGuestCount = form.Scenario1_ThreeWeekAverageGuestCount;
                   dbEntry.Scenario2_EstimatedDonation = form.Scenario2_EstimatedDonation;
                   dbEntry.Scenario2_EstimatedGuestCount = form.Scenario2_EstimatedGuestCount;
                   dbEntry.Scenario2_GuestCountInvited = form.Scenario2_GuestCountInvited;
                   dbEntry.Scenario2_TargetedGuestCount = form.Scenario2_TargetedGuestCount;
                   dbEntry.Scenario2_ThreeWeekAverageGuestCount = form.Scenario2_ThreeWeekAverageGuestCount;
                   dbEntry.TenPercentDonation = form.TenPercentDonation;
                   dbEntry.TotalDonation = form.TotalDonation;
                   dbEntry.Week1_45_AdjustedSales = form.Week1_45_AdjustedSales;
                   dbEntry.Week1_45_GuestCount = form.Week1_45_GuestCount;
                   dbEntry.Week1_56_AdjustedSales = form.Week1_56_AdjustedSales;
                   dbEntry.Week1_56_GuestCount = form.Week1_56_GuestCount;
                   dbEntry.Week1_67_AdjustedSales = form.Week1_67_AdjustedSales;
                   dbEntry.Week1_67_GuestCount = form.Week1_67_GuestCount;
                   dbEntry.Week1_78_AdjustedSales = form.Week1_78_AdjustedSales;
                   dbEntry.Week1_78_GuestCount = form.Week1_78_GuestCount;
                   dbEntry.Week1_89_AdjustedSales = form.Week1_89_AdjustedSales;
                   dbEntry.Week1_89_GuestCount = form.Week1_89_GuestCount;
                   dbEntry.Week1_AdjustedSalesTotal = form.Week1_AdjustedSalesTotal;
                   dbEntry.Week1_GuestCountTotal = form.Week1_GuestCountTotal;
                   dbEntry.Week1Date = form.Week1Date;
                   dbEntry.Week2_45_AdjustedSales = form.Week2_45_AdjustedSales;
                   dbEntry.Week2_45_GuestCount = form.Week2_45_GuestCount;
                   dbEntry.Week2_56_AdjustedSales = form.Week2_56_AdjustedSales;
                   dbEntry.Week2_56_GuestCount = form.Week2_56_GuestCount;
                   dbEntry.Week2_67_AdjustedSales = form.Week2_67_AdjustedSales;
                   dbEntry.Week2_67_GuestCount = form.Week2_67_GuestCount;
                   dbEntry.Week2_67_GuestCount = form.Week2_67_GuestCount;
                   dbEntry.Week2_78_AdjustedSales = form.Week2_78_AdjustedSales;
                   dbEntry.Week2_78_GuestCount = form.Week2_78_GuestCount;
                   dbEntry.Week2_89_AdjustedSales = form.Week2_89_AdjustedSales;
                   dbEntry.Week2_89_GuestCount = form.Week2_89_GuestCount;
                   dbEntry.Week2_AdjustedSalesTotal = form.Week2_AdjustedSalesTotal;
                   dbEntry.Week2_GuestCountTotal = form.Week2_GuestCountTotal;
                   dbEntry.Week2Date = form.Week2Date;
                   dbEntry.Week3_45_AdjustedSales = form.Week3_45_AdjustedSales;
                   dbEntry.Week3_45_GuestCount = form.Week3_45_GuestCount;
                   dbEntry.Week3_56_AdjustedSales = form.Week3_56_GuestCount;
                   dbEntry.Week3_67_AdjustedSales = form.Week3_67_AdjustedSales;
                   dbEntry.Week3_67_GuestCount = form.Week3_67_GuestCount;
                   dbEntry.Week3_78_AdjustedSales = form.Week3_78_AdjustedSales;
                   dbEntry.Week3_78_GuestCount = form.Week3_78_GuestCount;
                   dbEntry.Week3_89_AdjustedSales = form.Week3_89_AdjustedSales;
                   dbEntry.Week3_89_GuestCount = form.Week3_89_GuestCount;
                   dbEntry.Week3_AdjustedSalesTotal = form.Week3_AdjustedSalesTotal;
                   dbEntry.Week3_GuestCountTotal = form.Week3_GuestCountTotal;
                   dbEntry.Week3Date = form.Week3Date;
                   dbEntry.WeekDayOfPartnership = form.WeekDayOfPartnership;
               }
               }

               db.SaveChanges();
        }
 public void AddCharity(Charity charity)
 {
     var db = new ApplicationDbContext();
     db.Charities.Add(charity);
     db.SaveChanges();
 }
 public void UpdatePartnershipNight(PartnershipNight pn)
 {
     var db = new ApplicationDbContext();
     if (pn.PartnershipNightId == 0)
         db.PartnershipNights.Add(pn);
     else
     {
         PartnershipNight dbEntry = db.PartnershipNights.Find(pn.PartnershipNightId);
         if (dbEntry != null)
         {
             dbEntry.StartDate = pn.StartDate;
             dbEntry.EndDate = pn.EndDate;
             dbEntry.Comments = pn.Comments;
             dbEntry.Charity = db.Charities.Find(pn.Charity.CharityId);
             dbEntry.BVLocation = db.BvLocations.Find(pn.BVLocation.BvLocationId);
         }
     }
     db.SaveChanges();
 }
 public void AddBvLocation(BvLocation bvLocation)
 {
     var db = new ApplicationDbContext();
     db.BvLocations.Add(bvLocation);
     db.SaveChanges(); ;
 }
 public void UpdatePartnershipNight(PartnershipNight pn)
 {
     var db = new ApplicationDbContext();
     if (pn.PartnershipNightId == 0)
     {
         pn.BVLocation = db.BvLocations.Find(pn.BVLocation.BvLocationId);
         pn.Charity = db.Charities.Find(pn.Charity.CharityId);
         db.PartnershipNights.Add(pn);
     }
     else
     {
         PartnershipNight dbEntry = db.PartnershipNights.Find(pn.PartnershipNightId);
         if (dbEntry != null)
         {
             dbEntry.StartDate = pn.StartDate;
             dbEntry.EndDate = pn.EndDate;
             dbEntry.AfterTheEventFinished = pn.AfterTheEventFinished;
             dbEntry.BeforeTheEventFinished = pn.BeforeTheEventFinished;
             dbEntry.CheckRequestFinished = pn.CheckRequestFinished;
             dbEntry.CheckRequestId = pn.CheckRequestId;
             dbEntry.Comments = pn.Comments;
             dbEntry.Charity = db.Charities.Find(pn.Charity.CharityId);
             dbEntry.BVLocation = db.BvLocations.Find(pn.BVLocation.BvLocationId);
         }
     }
     db.SaveChanges();
 }