示例#1
0
 public void Delete(TEntity entity)
 {
     if (db.Entry(entity).State == EntityState.Detached)
     {
         dbSet.Attach(entity);
     }
     dbSet.Remove(entity);
     db.SaveChanges();
 }
示例#2
0
        public IHttpActionResult PutUser(int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.UserID)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#3
0
        public ActionResult Update(IEnumerable <ProductViewModel> products)
        {
            using (var northwind = new NORTHWNDEntities())
            {
                //Iterate all updated products which are posted by the Kendo Grid
                foreach (var productViewModel in products)
                {
                    // Create a new Product entity and set its properties from productViewModel
                    var product = new Product
                    {
                        ProductID    = (int)productViewModel.ProductID,
                        ProductName  = productViewModel.ProductName,
                        UnitPrice    = productViewModel.UnitPrice,
                        UnitsInStock = productViewModel.UnitsInStock,
                        Discontinued = productViewModel.Discontinued
                    };

                    // Attach the entity
                    northwind.Products.Attach(product);
                    // Change its state to Modified so Entity Framework can update the existing product instead of creating a new one
                    //northwind.ObjectStateManager.ChangeObjectState(product, EntityState.Modified);
                    northwind.Entry(product).State = EntityState.Modified;
                }

                // Save all updated products to the database
                northwind.SaveChanges();

                //Return emtpy result
                return(Json(null));
            }
        }
示例#4
0
        // PUT api/Product/5
        public async Task <IHttpActionResult> PutProduct(int id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.ProductID)
            {
                return(BadRequest());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> PutCategories(int id, Categories categories)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != categories.CategoryID)
            {
                return(BadRequest());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoriesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#6
0
        public ActionResult Edit(Employee e, string btnSave)
        {
            if (btnSave == "Save")
            {
                if (!ModelState.IsValid)
                {
                    return(RedirectToAction("Index"));
                }

                NORTHWNDEntities nwe = new NORTHWNDEntities();
                nwe.Configuration.ProxyCreationEnabled = false;
                Employee original = nwe.Employees.Where(emp => emp.EmployeeID == employeeId).SingleOrDefault();

                foreach (PropertyInfo propertyInfo in ((Employee)original).GetType().GetProperties())
                {
                    if (propertyInfo.GetValue(e) == null)
                    {
                        propertyInfo.SetValue(e, propertyInfo.GetValue(original));
                    }
                }
                nwe.Entry(original).CurrentValues.SetValues(e);
                nwe.SaveChanges();

                return(View("ProfileView", e));
            }
            else
            {
                return(View("Index"));
            }
        }
示例#7
0
        public virtual bool Update(T entity)
        {
            bool result;

            if (entity == null)
            {
                result = false;
            }
            else
            {
                result = true;
            }

            Context.Entry(entity).State = EntityState.Modified;

            return(result);
        }
示例#8
0
 public void Update(Customer customer)
 {
     using (NORTHWNDEntities context = new NORTHWNDEntities())
     {
         context.Customers.Attach(customer);
         context.Entry(customer).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
示例#9
0
 public string Update(Employee employee)
 {
     if (!ModelState.IsValid)
     {
         return("Invalid model");
     }
     _db.Entry(employee).State = EntityState.Modified;
     _db.SaveChanges();
     return("Updated successfully");
 }
示例#10
0
 public ActionResult Edit([Bind(Include = "CustomerID,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax")] Customers customers)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customers).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customers));
 }
示例#11
0
 public ActionResult Edit([Bind(Include = "UserID,UserName,Password")] Login login)
 {
     if (ModelState.IsValid)
     {
         db.Entry(login).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(login));
 }
示例#12
0
 public ActionResult Edit([Bind(Include = "user_name,phone,email,pass,role")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
 public ActionResult Edit([Bind(Include = "ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] Products products)
 {
     if (ModelState.IsValid)
     {
         db.Entry(products).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(products));
 }
 public ActionResult Edit([Bind(Include = "OrderID,CustomerID,EmployeeID,OrderDate,RequiredDate,ShippedDate,ShipVia,Freight,ShipName,ShipAddress,ShipCity,ShipRegion,ShipPostalCode,ShipCountry")] Order order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(order));
 }
示例#15
0
 public ActionResult Edit([Bind(Include = "CategoryID,CategoryName,Description,Picture")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
示例#16
0
        /// <summary>
        /// Updates existing product (only unit price and product name is modified)
        /// </summary>
        /// <param name="product">Product to be updated</param>
        /// <returns>Number of records updated</returns>
        public async Task <int> UpdateProduct(Product product)
        {
            using (var dbContext = new NORTHWNDEntities())
            {
                Product productEntity = await dbContext.Products.FindAsync(product.ProductID);

                productEntity.UnitPrice = product.UnitPrice;
                dbContext.Entry(productEntity).State = EntityState.Modified;
                return(await dbContext.SaveChangesAsync());
            }
        }
 public ActionResult Edit(Employees employees)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employees).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ReportsTo = new SelectList(db.Employees, "EmployeeID", "LastName", employees.ReportsTo);
     return(View(employees));
 }
示例#18
0
 public ActionResult Edit(depart d)
 {
     if (ModelState.IsValid)
     {
         NORTHWNDEntities db = new NORTHWNDEntities();
         db.Entry(d).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("index"));
     }
     return(View());
 }
示例#19
0
 public ActionResult Edit([Bind(Include = "EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath")] Employees employees)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employees).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ReportsTo = new SelectList(db.Employees, "EmployeeID", "LastName", employees.ReportsTo);
     return(View(employees));
 }
示例#20
0
        // Update
        public ProductViewModel UpdateProduct(ProductViewModel productVM)
        {
            using (var context = new NORTHWNDEntities())
            {
                Product product = new Product();
                Mapper.Map(productVM, product);

                context.Entry(product).State = EntityState.Modified;
                context.SaveChanges();
                return(productVM);
            }
        }
示例#21
0
 public ActionResult Edit(Products products)
 {
     if (ModelState.IsValid)
     {
         db.Entry(products).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", products.CategoryID);
     ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "CompanyName", products.SupplierID);
     return(View(products));
 }
示例#22
0
        // Update
        public SupplierViewModel UpdateSupplier(SupplierViewModel supplierVM)
        {
            using (var context = new NORTHWNDEntities())
            {
                Supplier supplier = new Supplier();
                Mapper.Map(supplierVM, supplier);

                context.Entry(supplier).State = EntityState.Modified;
                context.SaveChanges();
                return(supplierVM);
            }
        }
示例#23
0
 public ActionResult Edit([Bind(Include = "ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", product.CategoryID);
     ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "CompanyName", product.SupplierID);
     return(View(product));
 }
示例#24
0
 public ActionResult Edit([Bind(Include = "OrderID,CustomerID,EmployeeID,OrderDate,RequiredDate,ShippedDate,ShipVia,Freight,ShipName,ShipAddress,ShipCity,ShipRegion,ShipPostalCode,ShipCountry")] Orders orders)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orders).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CompanyName", orders.CustomerID);
     ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "LastName", orders.EmployeeID);
     ViewBag.ShipVia    = new SelectList(db.Shippers, "ShipperID", "CompanyName", orders.ShipVia);
     return(View(orders));
 }
示例#25
0
 public void Update(Category category)
 {
     #region I.yol
     //var updated = db.Categories.Find(category.CategoryID);
     //updated.CategoryName = category.CategoryName;
     //updated.Description = category.Description;
     //db.SaveChanges();
     #endregion
     #region II.Yol
     db.Entry(category).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     #endregion
 }
        public bool UpdateCustomer(Customer customer)
        {
            _dbContext.Entry(customer).State = System.Data.Entity.EntityState.Modified;
            int result = _dbContext.SaveChanges();

            if (result > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#27
0
        public ActionResult Edit(Order model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            using (var context = new NORTHWNDEntities())
            {
                context.Orders.Attach(model);
                context.Entry(model).State = EntityState.Modified;
                context.SaveChanges();
            }
            return(RedirectToAction("Edit", new { id = model.OrderID }));
        }
示例#28
0
        // Update
        public void UpdateCategory(IEnumerable <CategoryViewModel> categories)
        {
            using (var context = new NORTHWNDEntities())
            {
                foreach (var categoryViewModel in categories)
                {
                    Category category = new Category();
                    Mapper.Map(categoryViewModel, category);

                    context.Categories.Attach(category);
                    context.Entry(category).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
        public ActionResult Edit(Employee e, string btnSave)
        {
            if (btnSave == "Save")
            {
                if (!ModelState.IsValid)
                    return RedirectToAction("Index");

                NORTHWNDEntities nwe = new NORTHWNDEntities();
                nwe.Configuration.ProxyCreationEnabled = false;
                Employee original = nwe.Employees.Where(emp => emp.EmployeeID == employeeId).SingleOrDefault();

                foreach (PropertyInfo propertyInfo in ((Employee)original).GetType().GetProperties())
                {
                    if (propertyInfo.GetValue(e) == null)
                        propertyInfo.SetValue(e, propertyInfo.GetValue(original));
                }
                nwe.Entry(original).CurrentValues.SetValues(e);
                nwe.SaveChanges();

                return View("ProfileView", e);
            }
            else
                return View("Index");
        }
 public ActionResult Guncel(Products product)
 {
     db.Entry(product).State = EntityState.Modified;
     db.SaveChanges();
     return(Json(product, JsonRequestBehavior.AllowGet));
 }
示例#31
0
 public void SaveCustomer(Customers customer)
 {
     db.Entry(customer).State = EntityState.Modified;
     db.SaveChanges();
 }