public PartnershipNight GetPartnershipNightById(int partnershipNightId)
 {
     var db = new ApplicationDbContext();
     return (from pnight in db.PartnershipNights.Include("Charity").Include("BVLocation")
             where pnight.PartnershipNightId == partnershipNightId
             select pnight).FirstOrDefault();
 }
        public IQueryable<Entities.Form> GetForms()
        {
            var db = new ApplicationDbContext();

            return (from form in db.Forms
                    select form).AsQueryable<Form>();
        }
 public PartnershipNight GetPartnershipNightByDate(DateTime date, BvLocation loc)
 {
     var db = new ApplicationDbContext();
     return (from pnight in db.PartnershipNights.Include("Charity").Include("BVLocation")
             where pnight.StartDate == date && pnight.BVLocation == loc
             select pnight).FirstOrDefault();
 }
        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 BvLocation GetBvLocation(string storeNum)
 {
     var db = new ApplicationDbContext();
     return (from l in db.BvLocations
             where l.BvStoreNum == storeNum
             select l).FirstOrDefault();
 }
 public Entities.BvLocation GetBvLocation(int bvLocationId)
 {
     var db = new ApplicationDbContext();
     return (from l in db.BvLocations
             where l.BvLocationId == bvLocationId
             select l).FirstOrDefault();
 }
        //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 Charity GetCharityById(int id)
 {
     //throw new NotImplementedException();
     var db = new ApplicationDbContext();
     return (from charity in db.Charities
             where charity.CharityId == id
             select charity).FirstOrDefault();
 }
 public Charity GetCharityByName(string name)
 {
     //throw new NotImplementedException();
     var db = new ApplicationDbContext();
     return (from charity in db.Charities
             where charity.Name == name
             select charity).FirstOrDefault();
 }
 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 GetFormById(int id)
        {
            var db = new ApplicationDbContext();

            return (from form in db.Forms
                    where form.FormId == id
                    select form).FirstOrDefault();
        }
 public List<PartnershipNight> GetPartnershipNights(BvLocation l)
 {
     var db = new ApplicationDbContext();
     List<PartnershipNight> partnershipnights = (from c in db.PartnershipNights.Include("BvLocation").Include("Charity")
                                                 where c.BVLocation.BvLocationId == l.BvLocationId
                                                 select c).ToList<PartnershipNight>();
     return partnershipnights;
 }
 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;
 }
 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;
 }
 //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 ActionResult StoreProfile(int bvLocationId)
        {
            var db = new ApplicationDbContext();
            var loc = lRepo.GetBvLocation(bvLocationId);
            List<PartnershipNight> events = (from e in db.PartnershipNights.Include("BvLocation").Include("Charity")
                                         where e.BVLocation.BvLocationId == bvLocationId
                                         select e).ToList<PartnershipNight>();
            if (events.Count > 0)
            {
                TempData["message"] = string.Format("Profile for Restaurant Number:  {0}", loc.BvStoreNum);

                return View(events);
            }
            else
            {
                TempData["message"] = string.Format("Restaurant {0} has no Partnership Nights Yet", loc.BvStoreNum);

                return RedirectToAction("Index", "Profiles");
            }
        }
        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 List<Form> GetCompleteLeaders()
        {
            var db = new ApplicationDbContext();

            // Get a list of complete partnership night forms, in order by the actual total sales
            var leaderForms = (from f in db.Forms
                                where f.IsComplete == true
                                orderby f.ActualSalesTotal descending
                                select f).Take(10).ToList<Form>();

            var forms = new List<Form>();

            // Add the forms to the list
            foreach (var f in leaderForms)
            {
                forms.Add(new Form {
                    HostingRestaurant = f.HostingRestaurant, NameOnCheck = f.NameOnCheck, Purpose = f.Purpose,
                    DateOfPartnership = f.DateOfPartnership, ActualSalesTotal = f.ActualSalesTotal,
                    ActualGuestCountTotal = f.ActualGuestCountTotal, PosiDonations = f.PosiDonations });
            }

            // Return the list of partnership nights
            return forms;
        }
        public async Task<ActionResult> UserEdit(EditUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var Db = new ApplicationDbContext();
                var user = Db.Users.First(u => u.Id == model.UserId);
                if (user != null)
                {
                    user.UserName = model.UserName;
                    user.FirstName = model.FirstName;
                    user.LastName = model.LastName;
                    user.Email = model.Email;
                    user.Role = model.Role;
                    user.BvLocation = Db.BvLocations.Find(model.BvLocationId);

                    var rm = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));

                    if (rm.RoleExists("Admin") && rm.RoleExists("User"))
                    {
                        var idManager = new IdentityManager();
                        if (user.Role == "Admin")
                        {
                            idManager.AddUserToRole(user.Id, "Admin");
                        }
                        if (user.Role == "User")
                        {
                            idManager.AddUserToRole(user.Id, "User");
                        }
                    }


                    Db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                    await Db.SaveChangesAsync();
                }
                return RedirectToAction("UserIndex");
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult UserEdit(string id)
        {
            var Db = new ApplicationDbContext();

            var user = Db.Users.First(u => u.Id == id);
            var model = new EditUserViewModel(user);
            //pNt.Locations = lRepo.GetBvLocations().ToList<BvLocation>();
            model.BvLocations = lRepo.GetBvLocations().ToList<BvLocation>();

            return View(model);
        }
        //[Authorize(Roles = "Admin")]
        public ActionResult UserIndex()
        {
            var db = new ApplicationDbContext();

            List<ApplicationUser> users = db.Users.ToList();

            return View(users);
        }
        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 AddForm(Form form)
        {
            var db = new ApplicationDbContext();

            db.Forms.Add(form);
        }
 public IQueryable<Charity> GetCharities()
 {
     var db = new ApplicationDbContext();
     return (from charity in db.Charities
             select charity).AsQueryable<Charity>();
 }
 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 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");
        }
        //Location
        //***********************************

        //[Authorize(Roles = "Admin")]
        public ActionResult LocationIndex()
        {
            //need to get a list of all users
            var db = new ApplicationDbContext();
            List<BvLocation> locations = (from l in db.BvLocations
                                select l).ToList<BvLocation>();
            return View(locations);
        }
 public void AddCharity(Charity charity)
 {
     var db = new ApplicationDbContext();
     db.Charities.Add(charity);
     db.SaveChanges();
 }