Exemplo n.º 1
0
        public void Remove(Project entity)
        {
            var oldState = Get(entity.Id);

            if (Version.Next(oldState.Version) > entity.Version)
            {
                throw new DbUpdateConcurrencyException("This version is not the most updated for this object.");
            }

            var entry = entity.ToProjectState();

            DbContext.Projects.Remove(entry);
        }
Exemplo n.º 2
0
        // https://docs.microsoft.com/en-us/ef/core/saving/disconnected-entities

        public void Add(User entity)
        {
            var entry = entity.ToUserState();

            var oldState = Get(entity.Id);

            if (oldState.Equals(User.Empty()))
            {
                DbContext.Users.Add(entry);
            }
            else
            {
                if (Version.Next(oldState.Version) > entity.Version)
                {
                    throw new DbUpdateConcurrencyException("This version is not the most updated for this object.");
                }

                DbContext.Entry(oldState).CurrentValues.SetValues(entry);
            }
        }
Exemplo n.º 3
0
        // https://docs.microsoft.com/en-us/ef/core/saving/disconnected-entities

        public void Add(Project entity)
        {
            var entry    = entity.ToProjectState();
            var oldState = DbContext.Projects
                           .OrderByDescending(ob => ob.Id)
                           .ThenByDescending(ob => ob.RowVersion)
                           .FirstOrDefault(t => t.Id == entity.Id.Value);

            if (oldState == null)
            {
                DbContext.Projects.Add(entry);
            }
            else
            {
                var version = Version.From(BitConverter.ToInt32(oldState.RowVersion));

                if (Version.Next(version) > entity.Version)
                {
                    throw new DbUpdateConcurrencyException("This version is not the most updated for this object.");
                }

                DbContext.Entry(oldState).CurrentValues.SetValues(entry);
            }
        }