public bool UpdateCustomer(customer customerObj) { Models.ApartmentEntities entities = new Models.ApartmentEntities(); try { Models.customer customerModel = entities.customers.FirstOrDefault(el => el.id.Equals(customerObj.id) && el.first_name.Equals(customerObj.first_name) && el.last_name.Equals(customerObj.last_name)); if (customerModel != null) { customerModel.id = customerObj.id; customerModel.first_name = customerObj.first_name; customerModel.last_name = customerObj.last_name; customerModel.email = customerObj.email; customerModel.address = customerObj.address; customerObj.password = customerObj.password; entities.Entry(customerModel).State = System.Data.Entity.EntityState.Modified; entities.SaveChanges(); return(true); } else { return(false); } } catch (Exception ex) { return(false); } }
public static Models.customer CustomerObjToModel(Types.customer obj) { Models.customer model = new Models.customer { id = obj.id, first_name = obj.first_name, last_name = obj.last_name, email = obj.email, address = obj.address, password = obj.password }; return(model); }
public static Types.customer CustomerModelToObj(Models.customer model) { Types.customer obj = new Types.customer { id = model.id, first_name = model.first_name, last_name = model.last_name, email = model.email, address = model.address, password = model.password }; return(obj); }
public bool AddCustomer(customer customerObj) { Models.ApartmentEntities entities = new Models.ApartmentEntities(); try { Models.customer customerModel = ApartmentTypeConverter.CustomerObjToModel(customerObj); entities.customers.Add(customerModel); entities.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
private void btn_hapus_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var index = gridView1.GetSelectedRows(); if (index.Count() > 0) { if (Helpers.Generic.MsgQuestion("Hapus data yang dipilih?") == DialogResult.Yes) { var data = new Models.customer() { kd_customer = gridView1.GetRowCellValue(index[0], "kd_customer").ToString() }; Controllers.CCustomer.delete(data); } } this.init(); }
public static bool update(Models.customer data) { bool result = false; try { using (var db = new Models.jotunContext()) { db.Entry(data).State = EntityState.Modified; db.SaveChanges(); result = true; } } catch (Exception ex) { Helpers.Generic.MsgError(ex.Message); } return(result); }
public customer FindCustomer(int id, string firstName, string lastName, string taxNumber) { Models.ApartmentEntities entities = new Models.ApartmentEntities(); try { Models.customer customerModel = entities.customers.FirstOrDefault(el => el.id.Equals(id) && el.first_name.Equals(firstName) && el.last_name.Equals(lastName)); if (customerModel != null) { return(ApartmentTypeConverter.CustomerModelToObj(customerModel)); } else { return(null); } } catch (Exception ex) { return(null); } }
private void btn_simpan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var txt = new TextEdit[] { txt_nama, txt_alamat, txt_email, txt_no_telepon }; foreach (var t in txt) { if (t.EditValue.ToString() == "") { Helpers.Generic.MsgError(t.Tag.ToString() + " tidak boleh kosong"); t.Focus(); return; } } var data = new Models.customer() { kd_customer = txt_kd_customer.EditValue.ToString(), nama = txt_nama.EditValue.ToString(), alamat = txt_alamat.EditValue.ToString(), email = txt_email.EditValue.ToString(), no_telepon = txt_no_telepon.EditValue.ToString(), diskon = Convert.ToDouble(spin_diskon.EditValue), status = cbo_status.SelectedItem.ToString() }; if (this.Text.ToLower().Contains("tambah")) { Controllers.CCustomer.insert(data); } else { Controllers.CCustomer.update(data); } var frm = (FrmCustomer)this.Owner; frm.init(); this.Close(); }
public bool DeleteCustomer(customer customerObj) { Models.ApartmentEntities entities = new Models.ApartmentEntities(); try { Models.customer customerModel = entities.customers.FirstOrDefault(el => el.id.Equals(customerObj.id) && el.first_name.Equals(customerObj.first_name) && el.last_name.Equals(customerObj.last_name)); if (customerModel != null) { entities.Entry(customerModel).State = System.Data.Entity.EntityState.Deleted; entities.SaveChanges(); return(true); } else { return(false); } } catch (Exception ex) { return(false); } }