Пример #1
0
        public ActionResult Edit(ListingViewModel listingViewModel)
        {
            listingViewModel.PopulatePickupLocations(db);
            listingViewModel.PopulatePickupLocation(db);

            var saveListing = (from b in db.Listings where b.id == listingViewModel.id select b).FirstOrDefault();

            var pickupLocationsForGrower = db.PickupLocations.Where(m => m.Grower.Id == saveListing.Grower.Id);

            ViewBag.locationsList = new SelectList(pickupLocationsForGrower, "id", "name", saveListing.PickupLocation.id);

            saveListing.product        = listingViewModel.product;
            saveListing.qtyOffered     = listingViewModel.qtyOffered;
            saveListing.qtyLabel       = listingViewModel.qtyLabel;
            saveListing.harvested_date = listingViewModel.harvested_date;
            saveListing.expire_date    = listingViewModel.expire_date;
            saveListing.cost           = listingViewModel.cost;
            saveListing.available      = listingViewModel.available;
            saveListing.comments       = listingViewModel.comments;
            saveListing.PickupLocation = listingViewModel.PickupLocation;

            CheckListingForErrors(saveListing);

            if (ModelState.IsValid)
            {
                db.Entry(saveListing).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(listingViewModel));
        }