コード例 #1
0
        public UpdatedStatus Update(T updatedEntity)
        {
            UpdatedStatus operationStatus = UpdatedStatus.Failed;

            try
            {
                helpDeskContext _db = new helpDeskContext();
                T currentEntity     = _db.Set <T>().FirstOrDefault(ent => ent.Id == updatedEntity.Id);
                _db.Entry(currentEntity).OriginalValues["Timer"] = updatedEntity.Timer;
                _db.Entry(currentEntity).CurrentValues.SetValues(updatedEntity);

                if (_db.SaveChanges() == 1) //shoudl throw if stale;
                {
                    operationStatus = UpdatedStatus.Ok;
                }
            }
            catch (DbUpdateConcurrencyException dbx)
            {
                operationStatus = UpdatedStatus.Stale;
                Console.WriteLine("Problem in " + MethodBase.GetCurrentMethod().Name + dbx.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Problem in " + MethodBase.GetCurrentMethod().Name + ex.Message);
            }
            return(operationStatus);
        }
コード例 #2
0
 public HelpdeskRepository(helpDeskContext content = null)
 {
     _db = content != null ? content : new helpDeskContext();
 }