Exemplo n.º 1
0
        public async Task Update(MyMicrotingDbContext dbContext)
        {
            Organization organization = dbContext.Organizations.FirstOrDefault(x => x.Id == Id);

            if (organization == null)
            {
                throw new NullReferenceException($"Could not find Organization with {Id}");
            }

            organization.CustomerId           = CustomerId;
            organization.DomainName           = DomainName;
            organization.ServiceEmail         = ServiceEmail;
            organization.NumberOfLicenses     = NumberOfLicenses;
            organization.NumberOfLicensesUsed = NumberOfLicensesUsed;
            organization.UpToDateStatus       = UpToDateStatus;
            organization.NextUpgrade          = NextUpgrade;
            organization.InstanceStatus       = InstanceStatus;
            organization.InstanceId           = InstanceId;

            if (dbContext.ChangeTracker.HasChanges())
            {
                organization.UpdatedAt = DateTime.Now;
                organization.Version  += 1;
                await dbContext.SaveChangesAsync();

                dbContext.OrganizationVersions.Add(MapVersions(organization));
                await dbContext.SaveChangesAsync();
            }
        }
Exemplo n.º 2
0
        public async Task Create(MyMicrotingDbContext dbContext)
        {
            CreatedAt     = DateTime.UtcNow;
            UpdatedAt     = DateTime.UtcNow;
            Version       = 1;
            WorkflowState = Constants.WorkflowStates.Created;

            dbContext.Organizations.Add(this);
            await dbContext.SaveChangesAsync();

            dbContext.OrganizationVersions.Add(MapVersions(this));
            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async Task Create(MyMicrotingDbContext dbContext)
        {
            CreatedAt     = DateTime.UtcNow;
            UpdatedAt     = DateTime.UtcNow;
            Version       = 1;
            WorkflowState = Constants.WorkflowStates.Created;

            await dbContext.AddAsync(this);

            await dbContext.SaveChangesAsync();

            var res = MapVersion(this);

            if (res != null)
            {
                await dbContext.AddAsync(res);

                await dbContext.SaveChangesAsync();
            }
        }
Exemplo n.º 4
0
        public async Task Delete(MyMicrotingDbContext dbContext)
        {
            Organization organization = dbContext.Organizations.FirstOrDefault(x => x.Id == Id);

            if (organization == null)
            {
                throw new NullReferenceException($"Could not find Organization with {Id}");
            }

            organization.WorkflowState = Constants.WorkflowStates.Removed;

            if (dbContext.ChangeTracker.HasChanges())
            {
                organization.UpdatedAt = DateTime.Now;
                organization.Version  += 1;
                await dbContext.SaveChangesAsync();

                dbContext.OrganizationVersions.Add(MapVersions(organization));
                await dbContext.SaveChangesAsync();
            }
        }
Exemplo n.º 5
0
        private async Task UpdateInternal(MyMicrotingDbContext dbContext, string state = null)
        {
            if (state != null)
            {
                WorkflowState = state;
            }

            if (dbContext.ChangeTracker.HasChanges())
            {
                Version  += 1;
                UpdatedAt = DateTime.UtcNow;

                await dbContext.SaveChangesAsync();

                var res = MapVersion(this);
                if (res != null)
                {
                    await dbContext.AddAsync(res);

                    await dbContext.SaveChangesAsync();
                }
            }
        }