public IHttpActionResult Putproduct_tbl(int id, product_tbl product_tbl) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product_tbl.Id) { return(BadRequest()); } db.Entry(product_tbl).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!product_tblExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "id,idList,name,doc,img")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Create([Bind(Include = "id,name,img,describe,link")] news news) { if (ModelState.IsValid) { db.news.Add(news); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(news)); }
public ActionResult Create([Bind(Include = "id,idList,doc")] ListPro listPro) { if (ModelState.IsValid) { db.ListProes.Add(listPro); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idList = new SelectList(db.Products, "id", "name", listPro.idList); return(View(listPro)); }
public ActionResult Create(introduce new_introduce) { if (ModelState.IsValid) { db.introduces.Add(new_introduce); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(View(new_introduce)); } }
public ActionResult Create([Bind(Include = "id,name,img,describe,background")] partner partner) { if (ModelState.IsValid) { db.partners.Add(partner); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(View(partner)); } }
public HttpResponseMessage Delete(int id) { try { using (dataEntities entities = new dataEntities()) { //삭제한걸 또 삭제할 경우 Rmove 에 null 전달 후 예외 발생 //entities.Employees.Remove(entities.Employees.FirstOrDefault(e => e.ID == id)); var entity = entities.Employees.FirstOrDefault(e => e.ID == id); if (entity == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "Employee with Id = " + id.ToString() + " not Found to delete")); } else { entities.Employees.Remove(entity); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Put(int id, [FromBody] Employees employee) { // 500 internal server error 가 발생할 수 있다. using (dataEntities entities = new dataEntities()) { try { var entity = entities.Employees.FirstOrDefault(e => e.ID == id); if (entity == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "Employee with Id = " + id.ToString() + " not Found to update")); } else { entity.FirstName = employee.FirstName; entity.LastName = employee.LastName; entity.Gender = employee.Gender; entity.Salary = employee.Salary; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } } }
public string Putproduct([FromBody] product modifiedProduct) { using (dataEntities db = new dataEntities()) { try { var Product = db.products.Where(c => c.id == modifiedProduct.id).FirstOrDefault(); //Product = modifiedProduct; //db.Entry(Product).State = EntityState.Modified; Product.name = modifiedProduct.name; Product.NSX = modifiedProduct.NSX; Product.image1 = modifiedProduct.image1; Product.image1 = modifiedProduct.image2; Product.image1 = modifiedProduct.image3; Product.price = modifiedProduct.price; Product.unit = modifiedProduct.unit; db.SaveChanges(); return("Modify successfully"); } catch (Exception) { return("Modify fail"); } } }
public ActionResult Delete(int id) { using (dataEntities db = new dataEntities()) { DBtestUser emp = db.DBtestUsers.Where(x => x.Id == id).FirstOrDefault <DBtestUser>(); db.DBtestUsers.Remove(emp); db.SaveChanges(); return(Json(new { success = true, message = "Data Successfully Deleted" }, JsonRequestBehavior.AllowGet)); } }
private void SaveData(string path) { XRefMap xref = Microsoft.DocAsCode.Common.YamlUtility.Deserialize<XRefMap>(path); foreach (var spec in xref.References) { uidt t = new uidt(); t.uid = spec["uid"]; t.objectStr = Newtonsoft.Json.JsonConvert.SerializeObject(spec); db.uidts.Add(t); db.SaveChanges(); } }
public ActionResult AddSet(DBtestUser emp) { using (dataEntities db = new dataEntities()) { if (emp.Id == 0) { /* * string fileName = Path.GetFileNameWithoutExtension(emp.Ifile.FileName); * string extention = Path.GetExtension(emp.Ifile.FileName); * fileName = fileName + DateTime.Now.ToString("yymmssff") + extention; * emp.UAvatar = fileName; * emp.Ifile.SaveAs(Path.Combine(Server.MapPath("~/AppFile/Images"), fileName));*/ db.DBtestUsers.Add(emp); db.SaveChanges(); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } else { db.Entry(emp).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Update Successfully" }, JsonRequestBehavior.AllowGet)); } } }
public string Put([FromBody] product deletedProduct) { using (dataEntities db = new dataEntities()) { try { var deletedEmployee = db.products.Where(c => c.id == deletedProduct.id).FirstOrDefault(); deletedEmployee.status = false; db.SaveChanges(); return("Delete successfully"); } catch (Exception) { return("Delete fail"); } } }
public product Post([FromBody] product newProduct) { using (dataEntities da = new dataEntities()) { try { newProduct.status = true; da.products.Add(newProduct); da.SaveChanges(); return(newProduct); } catch { } return(null); } }
public HttpResponseMessage Post([FromBody] Employees employee) { try { using (dataEntities entities = new dataEntities()) { entities.Employees.Add(employee); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, employee); message.Headers.Location = new Uri(Request.RequestUri + employee.ID.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
// LogOut public ActionResult LogOut() { Session.Abandon(); db.SaveChanges(); return(RedirectToAction("Login")); }