Exemplo n.º 1
0
        public void Add(Friend value)
        {
            var added = _db.Friends.Add(value);
            _db.SaveChanges();

            Clients.All.add(added);
        }
Exemplo n.º 2
0
        public void Delete(Friend value)
        {
            var entity = _db.Friends.First<Friend>(f => f.Id == value.Id);
            var removed = _db.Friends.Remove(entity);
            _db.SaveChanges();

            Clients.All.delete(removed);
        }
Exemplo n.º 3
0
        public void Update(Friend value)
        {
            var updated = _db.Friends.First<Friend>(f => f.Id == value.Id);
            updated.Name = value.Name;
            _db.SaveChanges();

            Clients.All.update(updated);

            int removed;
            _locks.TryRemove(Context.ConnectionId, out removed);
            Clients.All.allLocks(_locks.Values);
        }
Exemplo n.º 4
0
        public void TakeLock(Friend value)
        {
            // Race condition: N clients attempting to edit same row
            lock (_lock)
            {
                foreach (int id in _locks.Values)
                {
                    if (value.Id == id)
                    {
                        return;
                    }
                }

                _locks.AddOrUpdate(Context.ConnectionId, value.Id, (key, oldValue) => value.Id);
                Clients.Caller.takeLockSuccess(value);
                Clients.All.allLocks(_locks.Values);
            }                        
        }