public ActionResult Customer_Update([DataSourceRequest] DataSourceRequest request, Customer customer)
 {
     //if (ModelState.IsValid)
     if (customer != null)
     {
         using (ECommerce db = new ECommerce())
         {
             var entity = new Customer()
             {
                 CustomerID       = customer.CustomerID,
                 CustomerPassword = customer.CustomerPassword,
                 email            = customer.email,
                 CustomerName     = customer.CustomerName,
                 State            = customer.State,
                 Address          = customer.Address,
                 ContactNumber    = customer.ContactNumber,
                 Role             = customer.Role
             };
             db.Customers.Attach(entity);
             db.Entry(entity).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     return(Json(new[] { customer }.ToDataSourceResult(request, ModelState)));
 }
 public ActionResult Employee_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable <Employee> emps)
 {
     db.Configuration.LazyLoadingEnabled = false;
     //db.Configuration.ProxyCreationEnabled = false;
     if (emps != null)
     {
         foreach (var emp in emps)
         {
             //var isIn = db.Employees.Where(s => s.EmpID.Equals(emp.Manager) && s.Manager.Equals(emp.EmpID));
             //var custEmpQuery = result.Where(c => c.Manager.Equals(emp.EmpID));
             //var isIn = result.Where(c => c.Manager.Equals(emp.EmpID));
             //bool isIn = result.Any(c => c.Manager.Equals(emp.EmpID));
             var result = MangerList(emp.EmpID);
             var a      = emp.Manager;
             if (!result.Any(s => s.EmpID.Equals(a)) && !emp.EmpID.Equals(emp.Manager))
             {
                 using (ECommerce db = new ECommerce())
                 {
                     var entity = new Employee()
                     {
                         EmpID        = emp.EmpID,
                         EmployeeName = emp.EmployeeName,
                         Manager      = emp.Manager
                     };
                     db.Employees.Attach(entity);
                     db.Entry(entity).State = EntityState.Modified;
                     db.SaveChanges();
                 }
                 return(Json(emps.ToDataSourceResult(request, ModelState)));
             }
         }
     }
     return(RedirectToAction("Employee_Read"));
 }
        public IHttpActionResult PutOrdine(int id, Ordine ordine)
        {
            log.Debug($"update dell'ordine num. {id}");
            if (!ModelState.IsValid)
            {
                log.Warn($"modello ordine non valido");
                return(BadRequest(ModelState));
            }

            if (id != ordine.NumeroOrdine)
            {
                log.Warn($"id ordine non coincidente {id} != {ordine.NumeroOrdine}");
                return(BadRequest());
            }

            db.Entry(ordine).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
                log.Info($"ordine num. {id} salvato");
            }
            catch (DbUpdateConcurrencyException e)
            {
                log.Error($"eccezione salvando ordine num. {id}", e);
                if (!OrdineExists(id))
                {
                    log.Warn($"l'ordine num. {id} non esiste");
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }