private void btnSubmit_Click(object sender, EventArgs e) { if (BaseValidator.IsFormValid(this.components)) { string IMGName = Guid.NewGuid().ToString() + Path.GetExtension(pcCustomer.ImageLocation); string path = Application.StartupPath + "/Images/"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } pcCustomer.Image.Save(path + IMGName); CustomerTB customer = new CustomerTB() { Address = txtAddress.Text, Email = txtEmail.Text, Phone = txtPhone.Text, FullName = txtName.Text, CustomerIMG = IMGName }; if (customerID == 0) { db.customerRepository.InsertCustomer(customer); } else { customer.CustomerID = customerID; db.customerRepository.UpdateCustomer(customer); } db.Save(); DialogResult = DialogResult.OK; } }
public IHttpActionResult PutCustomerTB(string id, CustomerTB customerTB) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != customerTB.Plate_Number) { return(BadRequest()); } db.Entry(customerTB).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CustomerTBExists(id)) { return(NotFound()); } throw; } return(StatusCode(HttpStatusCode.NoContent)); }
public bool UpdateCustomer(CustomerTB customer) { try { _db.Entry(customer).State = EntityState.Modified; return(true); } catch { return(false); } }
public bool DeleteCustomer(CustomerTB customer) { try { _db.Entry(customer).State = EntityState.Deleted; return(true); } catch { return(false); } }
public bool InsertCustomers(CustomerTB customer) { try { _db.CustomerTB.Add(customer); return(true); } catch { return(false); } }
public bool UpdateCustomer(CustomerTB customer) { var Local = db.Set <CustomerTB>() .Local .FirstOrDefault(f => f.CustomerID == customer.CustomerID); if (Local != null) { db.Entry(Local).State = EntityState.Detached; } ; db.Entry(customer).State = EntityState.Modified; return(true); }
public ActionResult Create(CustomerTB cust) { try { objcust.CustomerTBs.InsertOnSubmit(cust); objcust.SubmitChanges(); // TODO: Add insert logic here return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, CustomerTB cust) { try { var c2 = from c in objcust.CustomerTBs where c.CustomerId == id select c; c2.First().CustomerName = cust.CustomerName; c2.First().Age = cust.Age; c2.First().Email = cust.Email; c2.First().Gender = cust.Gender; objcust.SubmitChanges(); // TODO: Add update logic here return(RedirectToAction("Index")); } catch { return(View()); } }
private void btnSubmit_Click(object sender, EventArgs e) { using (ControlerDB db = new ControlerDB()) { string path = Application.StartupPath + "/Images/"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string imagename = Guid.NewGuid().ToString() + Path.GetExtension(pcCustomer.ImageLocation); pcCustomer.Image.Save(path + imagename); if (BaseValidator.IsFormValid(this.components)) { CustomerTB customer = new CustomerTB() { FullName = txtFullName.Text, Address = txtAddress.Text, Email = txtEmail.Text, Phone = txtPhone.Text, CustomerIMG = imagename }; if (userId == 0) { db.CustomersRepository.InsertCustomers(customer); } if (userId != 0) { customer.CustomerID = userId; db.CustomersRepository.UpdateCustomer(customer); } db.Save(); } DialogResult = DialogResult.OK; } }
public IHttpActionResult PostCustomerTB(CustomerTB customerTB) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.CustomerTBs.Add(customerTB); try { db.SaveChanges(); } catch (DbUpdateException) { if (CustomerTBExists(customerTB.Plate_Number)) { return(Conflict()); } throw; } return(CreatedAtRoute("DefaultApi", new { id = customerTB.Plate_Number }, customerTB)); }