public ActionResult Edit([Bind(Include = "ProductId,ProductName,Price,Comment,ApplicationUserId,CountryId,DistrictId,FileName,CreatedDate,IsDeleted")] Product product, HttpPostedFileBase Photo) { if (ModelState.IsValid) { string id = User.Identity.GetUserId(); product.ApplicationUserId = id; if (product != null) { if (Photo != null) { if (System.IO.File.Exists(Server.MapPath(product.Photo))) { System.IO.File.Delete(Server.MapPath(product.Photo)); } WebImage img = new WebImage(Photo.InputStream); FileInfo fotoinfo = new FileInfo(Photo.FileName); string newfoto = Guid.NewGuid().ToString() + fotoinfo.Extension; img.Resize(800, 350); img.Save("~/Content/Dosyalar/" + newfoto); product.Photo = "/Content/Dosyalar/" + newfoto; } db.Entry(product).State = EntityState.Modified; db.SaveChanges(); } } ViewBag.CountryId = new SelectList(db.Country, "CountryId", "CountryName", product.CountryId); return(RedirectToAction("Index")); }
public IHttpActionResult Putq_material_group(short id, q_material_group q_material_group) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != q_material_group.ForetagKod) { return(BadRequest()); } db.Entry(q_material_group).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!q_material_groupExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ProductResponse Delete(ProductRequest request) { ProductItem item = request.Product; var response = new ProductResponse(); using (var db = new ProductEntities()) { var model = new PRODUCT { ID = (int)item.Id }; var entry = db.Entry(model); if (entry.State == System.Data.Entity.EntityState.Detached) { db.PRODUCTS.Attach(model); } db.PRODUCTS.Remove(model); db.SaveChanges(); } return(response); }
public IHttpActionResult Putxakh(string id, xakh xakh) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != xakh.ArtKat) { return(BadRequest()); } db.Entry(xakh).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!xakhExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Putq_Customer_items_2_Jeeves(int id, q_Customer_items_2_Jeeves q_Customer_items_2_Jeeves) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != q_Customer_items_2_Jeeves.id) { return(BadRequest()); } db.Entry(q_Customer_items_2_Jeeves).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!q_Customer_items_2_JeevesExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ProductResponse SaveProduct(ProductRequest request) { ProductItem item = request.Product; var response = new ProductResponse(); using (var db = new ProductEntities()) { var model = new PRODUCT { NAME = item.Name, QUANTITY = item.Quantity, SALE_AMOUNT = item.SaleAmount }; if (item.Id == null) { db.PRODUCTS.Add(model); } else { model.ID = (int)item.Id; db.Entry(model).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); } return(response); }
public IHttpActionResult PutProduct(int id, Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product.Id) { return(BadRequest()); } db.Entry(product).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Delete(int id) { var stuffdel = DC.stuffs.Where(x => x.itemid == id).FirstOrDefault(); DC.Entry(stuffdel).State = System.Data.Entity.EntityState.Deleted; DC.SaveChanges(); return(Ok()); }
public bool DeleteProduct(int id) { try { var product = db.Products.Where(x => x.Id == id).FirstOrDefault(); if (product == null) { return(false); } db.Entry(product).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public ActionResult Edit([Bind(Include = "ProductId,ProductName,Price")] Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Edit([Bind(Include = "foretagkod,lagstalle,q_profit_center,q_material_group,q_isbn_no,artnr,artbeskr,q_itemtypecd1,q_artkat,artlistpris,momskod,itemstatuscode,q_sap_item_no,artstatnr,UpdateStatusDescr,itemtypecd2,q_wsoy_libraryclass,varugruppkod,q_fetched_by_inobiz,ar_q_edition_counter,artkalkber,artkalkpris,q_publisher_itemid,artvikt,q_publ_date,q_artbeskr_kiva,q_planned_arrival_date,q_pl_garr_date,ArtBeskrSpec,q_author,q_edt,q_aof,q_au,q_des,q_eic,q_ill,q_ot,q_pho,q_pre,q_rea,q_tra,itemtypecd3,q_print_year,q_size,q_original_title,q_series,q_series_id,q_series_partno,q_total_no_part_series,itemtypecd4,q_language,webpublish")] q_Customer_items_2_Jeeves q_Customer_items_2_Jeeves) { if (ModelState.IsValid) { db.Entry(q_Customer_items_2_Jeeves).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(q_Customer_items_2_Jeeves)); }
public bool Delete(int id) { //new NotImplementedException(); customers try { var customer = db.Customers.Where(x => x.id == id).FirstOrDefault(); if (customer == null) { return(false); } db.Entry(customer).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public ActionResult Edit([Bind(Include = "CustomerId,CardNumber,ExpirationDate,Cvv")] CardData cardData) { if (ModelState.IsValid) { db.Entry(cardData).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cardData)); }
public ActionResult Edit([Bind(Include = "Product_id,Product_name,Rate,Model_id")] Product_tbl product_tbl) { if (ModelState.IsValid) { db.Entry(product_tbl).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Model_id = new SelectList(db.ProductDetails, "Model_id", "Model_name", product_tbl.Model_id); return(View(product_tbl)); }
public ActionResult Edit(Product model) { ValidateProduct(model); if (ModelState.IsValid) { db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public bool Delete(String Id) { //throw new NotImplementedException(); //throw new NotImplementedException();s try { var product = db.Products.Where(x => x.id == Id).FirstOrDefault(); if (product == null) { return(false); } db.Entry(product).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public IHttpActionResult Modify(ProductModel productModel) { var product = new Table_DB_Product() { Name = productModel.Name, Id = productModel.Id, Price = productModel.Price }; _context.Entry(product).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); return(Ok("Success")); }
public bool Update(T t, object key) { try { if (t == null) { return(false); } T exist = context.Set <T>().Find(key); if (exist != null) { context.Entry(exist).CurrentValues.SetValues(t); context.SaveChanges(); } return(true); } catch (DbEntityValidationException e) { string error = ""; foreach (var eve in e.EntityValidationErrors) { foreach (var ve in eve.ValidationErrors) { error += String.Format("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"", ve.PropertyName, eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName), ve.ErrorMessage) + "<br>"; } } Debug.WriteLine(e.Message + "\n" + error); return(false); } catch (Exception e) { Debug.WriteLine(e.Message + "\n" + e.StackTrace); } return(true); }
public IHttpActionResult Update(ProductModel productModel) { var product = new product() { Id = productModel.Id, Name = productModel.Name, Qty = productModel.Qty, Price = productModel.Price, }; _context.Entry(product).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); return(Ok("Success")); }
public IHttpActionResult Put(int id, [FromBody] Product reuest) { string result = string.Empty; try { Product p = dbContext.Products.Where(x => x.ProductId == id).SingleOrDefault(); dbContext.Entry(p).CurrentValues.SetValues(result); dbContext.SaveChanges(); } catch (Exception) { throw; } return(Ok(result)); }
public ActionResult UpdateProduct(ProductViewModel model) { if (ModelState.IsValid) { var productToUpdate = dbContext.Products.Find(model.ProductId); productToUpdate.CategoryId = model.Category; productToUpdate.Description = model.Description; productToUpdate.Name = model.Name; productToUpdate.Price = model.Price.Value; productToUpdate.Quantity = model.Quantity.Value; dbContext.Entry(productToUpdate).State = System.Data.EntityState.Modified; dbContext.SaveChanges(); return(Json(new { success = true })); } else { return(Json(new { success = false })); } }
public ActionResult Edit(ApplicationUser model, HttpPostedFileBase Photo) { ApplicationUser user = db.Users.Where(x => x.Id == model.Id).FirstOrDefault(); if (user != null) { if (Photo != null) { if (System.IO.File.Exists(Server.MapPath(user.Photo))) { System.IO.File.Delete(Server.MapPath(user.Photo)); } WebImage img = new WebImage(Photo.InputStream).Resize(800, 300, false, true); FileInfo fotoinfo = new FileInfo(Photo.FileName); string newfoto = Guid.NewGuid().ToString() + fotoinfo.Extension; img.Save("~/Content/Dosyalar/" + newfoto); user.Photo = "/Content/Dosyalar/" + newfoto; } db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); }