예제 #1
0
        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);
        }
예제 #2
0
 /// <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)
         });
     }
 }
예제 #3
0
        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();
        }
예제 #4
0
 public void Update(Model m)
 {
     try
     {
         CurrentDbSet.Update(m);
     }
     catch (Exception ex)
     {
         Report.Notify(new RCM.Message(Codes.ERR_DB_UPD)
         {
             DetailedText = ex.ToString()
         });
     }
 }
예제 #5
0
        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();
            }
        }
예제 #6
0
 public virtual void Update(T item)
 {
     CurrentDbSet.Update(item);
     DbContext.SaveChanges();
 }