public virtual ServiceResult <T> Update(T item, bool saveImmediately = true) { var result = Validate(item); if (result.HasViolation) { return(result); } var editor = item as EditorEntity; if (editor != null) { if (ApplicationContext.CurrentUser != null) { editor.LastUpdateBy = ApplicationContext.CurrentUser.UserID; editor.LastUpdateByName = ApplicationContext.CurrentUser.UserName; } editor.LastUpdateDate = DateTime.Now; } CurrentDbSet.Update(item); if (saveImmediately) { DbContext.SaveChanges(); } return(result); }
/// <summary> /// Assign values to specified property of Model from local DbSet and propagate changes to DGV. /// </summary> /// <typeparam name="T">Type of Model property</typeparam> /// <param name="prop">Name of properrty of Model or Column from dgv</param> /// <param name="val">Value</param> public void FillDbSetValues <T>(string prop, T val) { try { CellValueChanged -= RDataGridView_CellValueChanged; foreach (var i in SelectedCells.OfType <DataGridViewCell>().Select(c => c.RowIndex).Where(c => c >= 0).Distinct()) { var m = CurrentDbSet.Where(mm => mm.Id == (int)Rows[i].Cells["Id"].Value).FirstOrDefault(); if (m == null) { continue; } var setPropValue = m.GetType().GetProperty(prop).GetSetMethod(); setPropValue.Invoke(m, new object[] { val }); CurrentDbSet.Update(m); } SaveChanges(); Refresh(); CellValueChanged += RDataGridView_CellValueChanged; } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_FILL_DB_VAL) { DetailedText = string.Join(Environment.NewLine, prop, ex.Message) }); } }
public virtual void Update(T item) { var editor = item as EditorEntity; if (editor != null && ApplicationContext.CurrentUser != null) { editor.LastUpdateBy = ApplicationContext.CurrentUser.UserID; editor.LastUpdateByName = ApplicationContext.CurrentUser.UserName; editor.LastUpdateDate = DateTime.Now; } CurrentDbSet.Update(item); DbContext.SaveChanges(); }
public void Update(Model m) { try { CurrentDbSet.Update(m); } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_DB_UPD) { DetailedText = ex.ToString() }); } }
public virtual void Update(T item, bool saveImmediately = true) { var editor = item as EditorEntity; if (editor != null) { if (ApplicationContext.CurrentUser != null) { editor.LastUpdateBy = ApplicationContext.CurrentUser.UserID; editor.LastUpdateByName = ApplicationContext.CurrentUser.UserName; } editor.LastUpdateDate = DateTime.Now; } CurrentDbSet.Update(item); if (saveImmediately) { DbContext.SaveChanges(); } }
public virtual void Update(T item) { CurrentDbSet.Update(item); DbContext.SaveChanges(); }