public async Task <bool> AddData(standarddetailtbl obj) { try { using (var context = new smlpobDB()) { var isExsist = (from x in context.standarddetailtbls where x.elementId == obj.elementId && x.stdId == obj.stdId select x).SingleOrDefault(); if (isExsist != null) { return(false); } context.standarddetailtbls.Add(obj); await context.SaveChangesAsync(); return(true); } } catch (Exception ex) { LogHelpers.source = this.GetType().Name; LogHelpers.message = ex.Message; LogHelpers.user = ""; LogHelpers.WriteLog(); } return(false); }
private void DoUpdate() { int id = 0; int.TryParse(TxtStdId.Text, out id); var data = new standarddetailtbl { stdDetailId = id, stdId = ParseInt(TxtStdId.SelectedValue), elementId = Convert.ToInt32(TxtElementCode.SelectedValue), modBy = currentUser, modDate = DatetimeHelper.GetDatetimeNow() }; var ret = standardDetailControl.UpdateData(id.ToString(), data); if (ret.Result) { ClearFields(); SetLayout(ModeForm.ViewData); Alert("Data berhasil diubah"); } else { Alert("Gagal mengubah data"); } }
public async Task <bool> UpdateData(string id, standarddetailtbl obj) { try { if (id != obj.stdId.ToString()) { return(false); } using (var context = new smlpobDB()) { var isExsist = (from x in context.standarddetailtbls where x.elementId == obj.elementId && x.stdId == obj.stdId select x).SingleOrDefault(); if (isExsist != null) { return(false); } context.standarddetailtbls.Attach(obj); context.Entry(obj).Property(x => x.stdId).IsModified = true; context.Entry(obj).Property(x => x.elementId).IsModified = true; context.Entry(obj).Property(x => x.modBy).IsModified = true; context.Entry(obj).Property(x => x.modDate).IsModified = true; await context.SaveChangesAsync(); return(true); } } catch (Exception ex) { LogHelpers.source = this.GetType().Name; LogHelpers.message = ex.Message; LogHelpers.user = ""; LogHelpers.WriteLog(); } return(false); }
private void DoSave() { var data = new standarddetailtbl { stdId = ParseInt(TxtStdId.SelectedValue), elementId = Convert.ToInt32(TxtElementCode.SelectedValue), creaBy = currentUser, creaDate = DatetimeHelper.GetDatetimeNow() }; var ret = standardDetailControl.AddData(data); if (ret.Result) { ClearFields(); SetLayout(ModeForm.ViewData); Alert("data berhasil disimpan"); } else { Alert("Gagal menyimpan data"); } }
private void BtnSubmit_Click(object sender, EventArgs e) { try { //update if (!string.IsNullOrEmpty(TxtID.Value)) { var IDS = int.Parse(TxtID.Value); var NewItem = (from x in context.standarddetailtbls where x.stdDetailId == IDS select x).FirstOrDefault(); NewItem.modBy = User.Identity.Name; NewItem.modDate = DateTime.Now; NewItem.stdId = Convert.ToInt32(DDStdId.SelectedValue); NewItem.elementCode = DDElement.SelectedValue; } else //add new { var NewItem = new standarddetailtbl() { }; NewItem.creaBy = "test"; NewItem.creaDate = DateTime.Now; NewItem.stdId = Convert.ToInt32(DDStdId.SelectedValue); NewItem.elementCode = DDElement.SelectedValue; context.standarddetailtbls.Add(NewItem); } context.SaveChanges(); PanelGrid.Visible = true; PanelInput.Visible = false; RefreshGrid(); } catch (Exception ex) { TxtStatus.Text = "gagal save --> " + ex.Message; } }