/// <summary>
 /// After testing an insert or update to the database, this can be called to clear
 /// an Farm object that failed and became stuck in the EF queue, so it does not
 /// affect subsequent tests.
 /// </summary>
 private void Cleanup()
 {
     try
     {
         _context.Entry(farm).State = EntityState.Detached;
     }
     catch (Exception)
     {  }
 }
Beispiel #2
0
        public ActionResult Edit([Bind(Include = "farmId,name,address,town,county,provinceCode,postalCode,homePhone,cellPhone,directions,dateJoined,lastContactDate")] farm farm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(farm).State = EntityState.Modified;
                    db.SaveChanges();
                    TempData["message"]     = "Farm " + farm.name + " update successfully";
                    TempData["messageType"] = "success";
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                TempData["message"]     = "Error updating farm: " + ex.GetBaseException().Message;
                TempData["messageType"] = "danger";
            }

            ViewBag.provinceCode = new SelectList(db.provinces.OrderBy(a => a.name), "provinceCode", "name", farm.provinceCode);
            return(View(farm));
        }