public async Task <bool> UpdateData(string id, analysistypetbl obj) { try { if (id != obj.analysisTypeName) { return(false); } using (var context = new smlpobDB()) { context.analysistypetbls.Attach(obj); context.Entry(obj).Property(x => x.description).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); }
public async Task <bool> AddData(analysistypetbl obj) { try { using (var context = new smlpobDB()) { context.analysistypetbls.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 DoSave() { var data = new analysistypetbl { analysisTypeName = this.TxtAnalysisTypeName.Text, description = this.TxtDescription.Text, creaBy = currentUser, creaDate = DatetimeHelper.GetDatetimeNow() }; var ret = analysisControl.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(TxtAnalysisTypeName.Text)) { var IDS = TxtAnalysisTypeName.Text; var NewItem = (from x in context.analysistypetbls where x.analysisTypeName == IDS select x).FirstOrDefault(); NewItem.modBy = User.Identity.Name; NewItem.modDate = DateTime.Now; NewItem.analysisTypeName = TxtAnalysisTypeName.Text; NewItem.description = TxtDescription.Text; } else //add new { var NewItem = new analysistypetbl() { }; NewItem.creaBy = "test"; NewItem.creaDate = DateTime.Now; NewItem.analysisTypeName = TxtAnalysisTypeName.Text; NewItem.description = TxtDescription.Text; context.analysistypetbls.Add(NewItem); } context.SaveChanges(); PanelGrid.Visible = true; PanelInput.Visible = false; RefreshGrid(); } catch (Exception ex) { TxtStatus.Text = "gagal save --> " + ex.Message; } }
private void DoUpdate() { string id = TxtAnalysisTypeName.Text; var data = new analysistypetbl { analysisTypeName = TxtAnalysisTypeName.Text, description = TxtDescription.Text, modBy = currentUser, modDate = DatetimeHelper.GetDatetimeNow() }; var ret = analysisControl.UpdateData(id, data); if (ret.Result) { ClearFields(); SetLayout(ModeForm.ViewData); Alert("Data berhasil diubah"); } else { Alert("Gagal mengubah data"); } }