예제 #1
0
        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);
            PartnershipNightVM temp   = new PartnershipNightVM()
            {
                AfterTheEventFinished  = pnight.AfterTheEventFinished,
                BeforeTheEventFinished = pnight.BeforeTheEventFinished,
                CheckRequestFinished   = pnight.CheckRequestFinished,
                BVLocation             = pnight.BVLocation,
                Charity            = pnight.Charity,
                StartDate          = pnight.StartDate,
                EndDate            = pnight.EndDate,
                Comments           = pnight.Comments,
                CheckRequestId     = pnight.CheckRequestId,
                PartnershipNightId = pnight.PartnershipNightId
            };

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

            //PNightEditViewModel vModel = new PNightEditViewModel();

            ////Set view model to corresponding partnership night values
            //vModel.PartnershipNight = pnight;

            //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>();

            return(View(temp));
        }
        public void UpdatePartnershipNight(PartnershipNightVM pn)
        {
            var db = new ApplicationDbContext();

            if (pn.PartnershipNightId == 0)
            {
                db.PartnershipNights.Add(new PartnershipNight()
                {
                    StartDate  = pn.StartDate,
                    EndDate    = pn.EndDate,
                    Comments   = pn.Comments,
                    Charity    = db.Charities.Find(pn.Charity.CharityId),
                    BVLocation = db.BvLocations.Find(pn.BVLocation.BvLocationId)
                });
            }
            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();
        }
예제 #3
0
        public ViewResult PartnershipNightCreate()
        {
            var pNt = new PartnershipNightVM();

            //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.BvLocations = lRepo.GetBvLocations().ToList <BvLocation>();
            pNt.Charities   = charRepo.GetCharities().ToList <Charity>();

            return(View("PartnershipNightEdit", pNt));
        }
예제 #4
0
        public ActionResult PartnershipNightEdit(PartnershipNightVM partnershipNightVM)
        {
            partnershipNightVM.BVLocation = lRepo.GetBvLocations().FirstOrDefault(bvl => bvl.BvLocationId == partnershipNightVM.BvLocationId);
            partnershipNightVM.Charity    = charRepo.GetCharities().FirstOrDefault(char1 => char1.CharityId == partnershipNightVM.CharityId);

            if (ModelState.IsValid)
            {
                pnRepo.UpdatePartnershipNight(partnershipNightVM);

                return(RedirectToAction("PartnershipNightIndex"));
            }


            return(View());



            //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();

            //    // Store the correct child objects
            //    pnight.Charity = charRepo.GetCharityById(partnershipNight.Charity.CharityId);
            //    pnight.BVLocation = lRepo.GetBvLocation(partnershipNight.BVLocation.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.StartDate.ToShortDateString(), pnight.BVLocation.BvStoreNum);
            //    return RedirectToAction("PartnershipNightIndex");
            //}
            //else
            //{
            //    // there is something wrong with the data values
            //    return View();
            //}
        }