public ActionResult Edit([Bind(Include = "DepartmentId,Name")] Department department)
 {
     if (ModelState.IsValid)
     {
         db.Entry(department).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(PartialView(department));
 }
示例#2
0
        public static Response SaveChanges(StoreApp1Context db)
        {
            try
            {
                db.SaveChanges();
                return(new Response {
                    Succeeded = true,
                });
            }
            catch (Exception ex)
            {
                var response = new Response {
                    Succeeded = false,
                };
                if (ex.InnerException != null &&
                    ex.InnerException.InnerException != null &&
                    ex.InnerException.InnerException.Message.Contains("_Index"))
                {
                    response.Message = "Hay un registro con el mismo valor";
                }
                else if (ex.InnerException != null &&
                         ex.InnerException.InnerException != null &&
                         ex.InnerException.InnerException.Message.Contains("REFERENCE"))
                {
                    response.Message = "El registro no se puede eliminar porque tiene valores relacionados";
                }
                else
                {
                    response.Message = ex.Message;
                }

                return(response);
            }
        }