public ActionResult PartnershipNightEdit(PNightEditViewModel pn)
        {
            var pnEvent = new PartnershipNight();

            if (pn.PartnershipNight.PartnershipNightId != 0)
            {
                pnEvent.PartnershipNightId = pn.PartnershipNight.PartnershipNightId;
            }
            pnEvent.EndDate                = pn.PartnershipNight.EndDate;
            pnEvent.StartDate              = pn.PartnershipNight.StartDate;
            pnEvent.AfterTheEventFinished  = pn.PartnershipNight.AfterTheEventFinished;
            pnEvent.BeforeTheEventFinished = pn.PartnershipNight.BeforeTheEventFinished;
            pnEvent.CheckRequestFinished   = pn.PartnershipNight.CheckRequestFinished;
            pnEvent.CheckRequestId         = pn.PartnershipNight.CheckRequestId;
            pnEvent.Comments               = pn.PartnershipNight.Comments;
            pnEvent.BVLocation             = lRepo.GetBvLocation(pn.PartnershipNight.BVLocation.BvLocationId);
            pnEvent.Charity                = charRepo.GetCharityById(pn.PartnershipNight.Charity.CharityId);

            if (pnEvent != null && pnEvent.BVLocation != null && pnEvent.Charity != null)
            {
                pnRepo.UpdatePartnershipNight(pnEvent);
                TempData["message"] = string.Format("Event for {0} has been saved", pn.PartnershipNight.Charity.Name);
                return(RedirectToAction("PartnershipNightIndex"));
            }
            else
            {
                return(View());
            }
        }
        public ActionResult Edit(PNightEditViewModel vmodel)
        {
            //PartnershipNight pnight = pnRepo.GetPartnershipNights().FirstOrDefault<PartnershipNight>(pn => pn.PartnershipNightId)

            if (ModelState.IsValid)
            {
                // Transfer view model values to a partnership night object
                PartnershipNight pnight = new PartnershipNight();
                pnight.PartnershipNightId = vmodel.PartnershipNightId;
                pnight.Date                   = vmodel.Date;
                pnight.Comments               = vmodel.Comments;
                pnight.CheckRequestId         = vmodel.CheckRequestId;
                pnight.CheckRequestFinished   = vmodel.CheckRequestFinished;
                pnight.BeforeTheEventFinished = vmodel.BeforeTheEventFinished;
                pnight.AfterTheEventFinished  = vmodel.AfterTheEventFinished;

                // Store the correct child objects
                pnight.Charity    = charRepo.GetCharities().FirstOrDefault(ch => ch.CharityId == vmodel.CharityId);
                pnight.BVLocation = bvlocRepo.GetBvLocations().FirstOrDefault(bvl => bvl.BvLocationId == vmodel.BVLocationId);

                // Save the changes to the partnership night
                pnRepo.UpdatePartnershipNight(pnight);
                TempData["message"] = string.Format("Partnership Night for BV Location {0}, {1} has been saved", pnight.Date.ToShortDateString(), pnight.BVLocation.BvStoreNum);
                return(RedirectToAction("Index"));
            }
            else
            {
                // there is something wrong with the data values
                return(View(vmodel));
            }
        }
        public ActionResult Edit(int partnershipNightId)
        {
            // Get the correct partnership night, and create a view model to store values in
            PartnershipNight    pnight = pnRepo.GetPartnershipNights().FirstOrDefault(pn => pn.PartnershipNightId == partnershipNightId);
            PNightEditViewModel vmodel = new PNightEditViewModel();

            //Set view model to corresponding partnership night values
            vmodel.PartnershipNightId = pnight.PartnershipNightId;
            vmodel.Date                   = pnight.Date;
            vmodel.CharityId              = pnight.Charity.CharityId;
            vmodel.BVLocationId           = pnight.BVLocation.BvLocationId;
            vmodel.CheckRequestId         = pnight.CheckRequestId;
            vmodel.Comments               = pnight.Comments;
            vmodel.CheckRequestFinished   = pnight.CheckRequestFinished;
            vmodel.BeforeTheEventFinished = pnight.BeforeTheEventFinished;
            vmodel.AfterTheEventFinished  = pnight.AfterTheEventFinished;

            //Set List variables to contain lists of child objects for selection in the view
            vmodel.Charities = charRepo.GetCharities().ToList <Charity>();
            vmodel.Locations = bvlocRepo.GetBvLocations().ToList <BvLocation>();

            //Set session variables to contain lists of child objects for selection in the view
            //Session["charities"] = charRepo.GetCharities().ToList<Charity>();
            //Session["bvlocations"] = bvlocRepo.GetBvLocations().ToList<BvLocation>();

            return(View(vmodel));
        }
        public ActionResult PartnershipNightEdit(int partnershipNightId)
        {
            TempData["Title"] = "Edit";

            // Get the correct partnership night, and create a view model to store values in
            PartnershipNight    pnight = pnRepo.GetPartnershipNightById(partnershipNightId);
            PNightEditViewModel temp   = new PNightEditViewModel();

            temp.PartnershipNight = pnight;
            temp.Locations        = lRepo.GetBvLocations().ToList <BvLocation>();
            temp.Charities        = charRepo.GetCharities().ToList <Charity>();

            return(View(temp));
        }
        public ViewResult PartnershipNightCreate()
        {
            var pNt = new PNightEditViewModel();

            //vmodel.StartDate = DateTime.Now;

            //Set List variables to contain lists of child objects for selection in the view
            //vmodel.Charities = charRepo.GetCharities().ToList<Charity>();
            //vmodel.Locations = lRepo.GetBvLocations().ToList<BvLocation>();
            TempData["Title"] = "Add New Partnership Night";

            pNt.Locations                  = lRepo.GetBvLocations().ToList <BvLocation>();
            pNt.Charities                  = charRepo.GetCharities().ToList <Charity>();
            pNt.PartnershipNight           = new PartnershipNight();
            pNt.PartnershipNight.StartDate = DateTime.Today;
            pNt.PartnershipNight.EndDate   = DateTime.Today;
            return(View("PartnershipNightEdit", pNt));
        }