public ActionResult DeleteConfirmed(int id)
        {
            FarmersMarket farmersMarket = db.FarmersMarkets.Find(id);

            db.FarmersMarkets.Remove(farmersMarket);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "FarmersMarketId,marketname,Schedule,Address,Products,ZipCode,GoogleMapId")] FarmersMarket farmersMarket)
 {
     if (ModelState.IsValid)
     {
         db.Entry(farmersMarket).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.GoogleMapId = new SelectList(db.GoogleMaps, "Id", "CurrentLocation", farmersMarket.GoogleMapId);
     return(View(farmersMarket));
 }
        // GET: FarmersMarkets/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FarmersMarket farmersMarket = db.FarmersMarkets.Find(id);

            if (farmersMarket == null)
            {
                return(HttpNotFound());
            }
            return(View(farmersMarket));
        }
        // GET: FarmersMarkets/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FarmersMarket farmersMarket = db.FarmersMarkets.Find(id);

            if (farmersMarket == null)
            {
                return(HttpNotFound());
            }
            ViewBag.GoogleMapId = new SelectList(db.GoogleMaps, "Id", "CurrentLocation", farmersMarket.GoogleMapId);
            return(View(farmersMarket));
        }
        public void Customizable()
        {
            using (Many<FarmersMarket>.ToMany<Farmer>.Setup().Connect(
                m => m.Vendors, EnsureContains, EnsureContainsNot,
                f => f.Outlets, EnsureContains, EnsureContainsNot))
            {
                var farmer1 = new Farmer();
                var market1 = new FarmersMarket();
                farmer1.Outlets.Count.Should().Be(0);
                market1.Vendors.Count.Should().Be(0);

                farmer1.Outlets.Add(market1);
                farmer1.Outlets.Count.Should().Be(1);
                market1.Vendors.Count.Should().Be(1);

                var farmer2 = new Farmer();
                var market2 = new FarmersMarket();
                farmer2.Outlets.Count.Should().Be(0);
                market2.Vendors.Count.Should().Be(0);
                farmer1.Outlets.Count.Should().Be(1);
                market1.Vendors.Count.Should().Be(1);

                market2.Vendors.Add(farmer2);
                farmer2.Outlets.Count.Should().Be(1);
                market2.Vendors.Count.Should().Be(1);
                farmer1.Outlets.Count.Should().Be(1);
                market1.Vendors.Count.Should().Be(1);

                market2.Vendors.Add(farmer1);
                farmer2.Outlets.Count.Should().Be(1);
                market2.Vendors.Count.Should().Be(2);
                farmer1.Outlets.Count.Should().Be(2);
                market1.Vendors.Count.Should().Be(1);

                market2.Vendors.Remove(farmer1);
                farmer2.Outlets.Count.Should().Be(1);
                market2.Vendors.Count.Should().Be(1);
                farmer1.Outlets.Count.Should().Be(1);
                market1.Vendors.Count.Should().Be(1);

                farmer2.Outlets.Remove(market2);
                farmer2.Outlets.Count.Should().Be(0);
                market2.Vendors.Count.Should().Be(0);
                farmer1.Outlets.Count.Should().Be(1);
                market1.Vendors.Count.Should().Be(1);
            }
        }
        public void SaveMarketName(FarmersMarketViewModel market)
        {
            try
            {
                FarmersMarket fm = new FarmersMarket()
                {
                    marketname = market.marketname,
                    Schedule   = market.Schedule,
                    Address    = market.Address,
                    Products   = market.Products
                };

                db.FarmersMarkets.Add(fm);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw;
            }


            RedirectToAction("Index");
        }
 private void EnsureContainsNot(FarmersMarket arg1, Farmer arg2)
 {
     if (arg1.Vendors.Contains(arg2))
         arg1.Vendors.Remove(arg2);
 }
 private void EnsureContains(FarmersMarket arg1, Farmer arg2)
 {
     if (!arg1.Vendors.Contains(arg2))
         arg1.Vendors.Add(arg2);
 }