Ejemplo n.º 1
0
        public async Task <EntityResult> AddEventAsync(Application app, Event evt, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (evt == null)
            {
                throw new ArgumentNullException(nameof(evt));
            }

            app.Events = new List <Event> {
                evt
            };
            Context.Attach(app);

            try
            {
                await Context.SaveChangesAsync(cancellationToken);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(EntityResult.Failed(ErrorDescriber.ConcurrencyFailure()));
            }

            return(EntityResult.Success);
        }
Ejemplo n.º 2
0
        public async Task <EntityResult> SetSubscribersAsync(Application app, IList <long> userList, CancellationToken cancellationToken)
        {
            var appUsers = await Context.Set <UserApplication>().Where(x => x.ApplicationId == app.Id).ToListAsync(cancellationToken);

            var appUserList = appUsers.Select(x => x.UserId).ToList();
            var list1       = userList.Except(appUserList).ToList();
            var list2       = appUserList.Except(userList).ToList();

            foreach (var i in list1)
            {
                Context.Add(new UserApplication {
                    UserId = i, ApplicationId = app.Id
                });
            }

            foreach (var i in list2)
            {
                var item = appUsers.First(x => x.UserId == i);
                Context.Remove(item);
            }

            try
            {
                await Context.SaveChangesAsync(cancellationToken);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(EntityResult.Failed(ErrorDescriber.ConcurrencyFailure()));
            }

            return(EntityResult.Success);
        }
Ejemplo n.º 3
0
        public async Task <EntityResult> SaveFileMetadataAsync(FileMetadata metadata, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (metadata == null)
            {
                throw new ArgumentNullException(nameof(metadata));
            }

            DbContext.Add(metadata);

            try
            {
                await DbContext.SaveChangesAsync(cancellationToken);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(EntityResult.Failed(ErrorDescriber.ConcurrencyFailure()));
            }

            return(EntityResult.Success);
        }
Ejemplo n.º 4
0
        public async Task <EntityResult> CreateAsync(Application app, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            Context.Add(app);

            try
            {
                await Context.SaveChangesAsync(cancellationToken);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(EntityResult.Failed(ErrorDescriber.ConcurrencyFailure()));
            }

            return(EntityResult.Success);
        }
Ejemplo n.º 5
0
        public async Task <EntityResult> AddEventAsync(long appId, Event evt, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (evt == null)
            {
                throw new ArgumentNullException(nameof(evt));
            }

            evt.ApplicationId = appId;
            Context.Add(evt);

            try
            {
                await Context.SaveChangesAsync(cancellationToken);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(EntityResult.Failed(ErrorDescriber.ConcurrencyFailure()));
            }

            return(EntityResult.Success);
        }