Example #1
0
 public ActionResult Edit([Bind(Include = "Id,CategoryId,Code,Name,Price,Stock,Description,Notes,Discount,DisplayPosition,Status,SortOrder,ImageUrl")] Product product)
 {
     if (ModelState.IsValid)
     {
         product.CreatedDate     = DateTime.Now;
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
     return(View(product));
 }
        public virtual void Update(TEntity entityToUpdate)
        {
            try
            {
                if (entityToUpdate == null)
                {
                    throw new ArgumentNullException("entity");
                }

                dbSet.Attach(entityToUpdate);
                context.Entry(entityToUpdate).State = EntityState.Modified;
                this.context.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                throw new Exception(GetFullErrorText(dbEx), dbEx);
            }
        }