예제 #1
0
        /// <summary>
        /// Update journey
        /// </summary>
        /// <param name="model">journey Model</param>
        /// <returns></returns>
        public async Task <BaseComponentResultRp> Update(int id, JourneyPutRp model)
        {
            var result    = new BaseComponentResultRp();
            var createdBy = this._identityGateway.GetIdentity();

            this._dbContext.ChangeTracker.AutoDetectChangesEnabled = true;

            var journey = await this._dbContext.Journeys.Include(c => c.Product).SingleAsync(c => c.Id == id);

            if (journey == null)
            {
                result.AddNotFound($"The Resource {id} doesn't exists.");
                return(result);
            }

            journey.Update(this._datetimeGateway.GetCurrentDateTime(), createdBy, model.Name,
                           model.AvailabilitySlo,
                           model.LatencySlo,
                           model.ExperienceSlo,
                           new SLAValue(model.AvailabilitySLA, model.LatencySLA),
                           model.Description,
                           model.Avatar, model.Leaders, model.Group);

            this._dbContext.Journeys.Update(journey);

            await this._dbContext.SaveChangesAsync();

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Update Feature
        /// </summary>
        /// <param name="model">Feature Model</param>
        /// <returns></returns>
        public async Task <BaseComponentResultRp> UpdateFeature(int id, FeaturePutRp model)
        {
            var result    = new BaseComponentResultRp();
            var createdBy = this._identityGateway.GetIdentity();

            this._dbContext.ChangeTracker.AutoDetectChangesEnabled = true;

            var feature = await this._dbContext.Features.Include(c => c.Product).SingleAsync(c => c.Id == id);

            if (feature == null)
            {
                result.AddNotFound($"The Resource {id} doesn't exists.");
                return(result);
            }


            feature.Update(this._datetimeGateway.GetCurrentDateTime(),
                           createdBy, model.Name,
                           model.Avatar,
                           model.Description);

            this._dbContext.Features.Update(feature);

            await this._dbContext.SaveChangesAsync();

            return(result);
        }
예제 #3
0
        public async Task <BaseComponentResultRp> UpdateCustomer(int id, CustomerPutRp model)
        {
            var result    = new BaseComponentResultRp();
            var createdBy = this._identityGateway.GetIdentity();

            this._dbContext.ChangeTracker.AutoDetectChangesEnabled = true;

            var customer = await this._dbContext.Customers.SingleAsync(c => c.Id == id);

            if (customer == null)
            {
                result.AddNotFound($"The Resource {id} doesn't exists.");
                return(result);
            }

            customer.Update(this._datetimeGateway.GetCurrentDateTime(), createdBy,
                            model.Name,
                            model.Avatar,
                            model.Leaders);

            this._dbContext.Update(customer);

            await this._dbContext.SaveChangesAsync();

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Delete journey
        /// </summary>
        /// <param name="key">journey Id</param>
        /// <returns></returns>
        public async Task <BaseComponentResultRp> Delete(int id)
        {
            var result     = new BaseComponentResultRp();
            var modifiedBy = this._identityGateway.GetIdentity();

            await this._dbContext.RemoveJourney(id);

            return(result);
        }
예제 #5
0
        public async Task <BaseComponentResultRp> Delete(int featureId, int sourceId)
        {
            var result = new BaseComponentResultRp();
            var entity = await this._dbContext.Indicators.Where(c => c.FeatureId == featureId && c.SourceId == sourceId).SingleOrDefaultAsync();

            if (entity != null)
            {
                this._dbContext.Indicators.Remove(entity);
                await this._dbContext.SaveChangesAsync();
            }
            return(result);
        }
예제 #6
0
        public async Task <BaseComponentResultRp> Delete(int id)
        {
            var result = new BaseComponentResultRp();

            var source = await this._dbContext.SourcesItems.SingleAsync(c => c.Id == id);

            this._dbContext.SourcesItems.Remove(source);

            await this._dbContext.SaveChangesAsync();

            return(result);
        }
예제 #7
0
        public async Task <BaseComponentResultRp> DeleteSource(int sourceId)
        {
            var result = new BaseComponentResultRp();

            var items = await this._dbContext.SourcesItems.Where(c => c.SourceId == sourceId).ToListAsync();

            foreach (var item in items)
            {
                this._dbContext.SourcesItems.Remove(item);
            }

            await this._dbContext.SaveChangesAsync();

            return(result);
        }
예제 #8
0
        public async Task <BaseComponentResultRp> UnRegisterSquad(int squadId, int featureId)
        {
            var result = new BaseComponentResultRp();
            var item   = await this._dbContext.SquadFeatures
                         .Include(c => c.Feature).Where(c => c.SquadId == squadId && c.FeatureId == featureId)
                         .SingleOrDefaultAsync();

            if (item != null)
            {
                this._dbContext.SquadFeatures.Remove(item);

                await this._dbContext.SaveChangesAsync();
            }

            return(result);
        }
예제 #9
0
        /// <summary>
        /// Delete appsetting
        /// </summary>
        /// <param name="key">AppSetting Keg</param>
        /// <returns></returns>
        public async Task <BaseComponentResultRp> DeleteAppSetting(string key)
        {
            var result = new BaseComponentResultRp();

            var appSetting = await this._dbContext.AppSettings.FirstOrDefaultAsync(c => c.Key.Equals(key));

            if (appSetting == null)
            {
                result.AddNotFound($"The Resource {key} doesn't exists.");
                return(result);
            }

            this._dbContext.Remove(appSetting);

            await this._dbContext.SaveChangesAsync();

            return(result);
        }
예제 #10
0
        public async Task <BaseComponentResultRp> CreateMember(MemberPostRp model)
        {
            var result    = new BaseComponentResultRp();
            var createdBy = this._identityGateway.GetIdentity();

            var squad = await this._dbContext.Squads.SingleAsync(c => c.Id == model.SquadId);

            var user = await this._dbContext.Users.SingleAsync(c => c.Id == model.UserId);

            var entity = MemberEntity.Factory.Create(squad.Id.Value, user.Id.Value, this._datetimeGateway.GetCurrentDateTime(), createdBy);

            this._dbContext.Members.Add(entity);
            await this._dbContext.SaveChangesAsync();

            result.AddResult("Id", entity.Id);

            return(result);
        }
예제 #11
0
        /// <summary>
        /// Delete Squad
        /// </summary>
        /// <param name="key">Squad Id</param>
        /// <returns></returns>
        public async Task <BaseComponentResultRp> DeleteSquad(int id)
        {
            var result     = new BaseComponentResultRp();
            var modifiedBy = this._identityGateway.GetIdentity();

            var squad = await this._dbContext.Squads.SingleAsync(c => c.Id == id);

            if (squad == null)
            {
                result.AddNotFound($"The Resource {id} doesn't exists.");
                return(result);
            }

            this._dbContext.Squads.Remove(squad);

            await this._dbContext.SaveChangesAsync();

            return(result);
        }
예제 #12
0
        /// <summary>
        /// Update appsetting
        /// </summary>
        /// <param name="model">AppSetting Model</param>
        /// <returns></returns>
        public async Task <BaseComponentResultRp> UpdateAppSetting(string key, AppSettingPutRp model)
        {
            var result     = new BaseComponentResultRp();
            var appSetting = await this._dbContext.AppSettings.FirstOrDefaultAsync(c => c.Key.Equals(key));

            if (appSetting == null)
            {
                result.AddNotFound($"The Resource {key} doesn't exists.");
                return(result);
            }

            appSetting.Value      = model.Value;
            appSetting.ModifiedBy = this._identityGateway.GetIdentity();
            appSetting.ModifiedOn = DateTime.UtcNow;

            this._dbContext.Update(appSetting);
            await this._dbContext.SaveChangesAsync();

            return(result);
        }
예제 #13
0
        public async Task <BaseComponentResultRp> CreateSquadProduct(SquadProductPostRp model)
        {
            var result = new BaseComponentResultRp();

            var createdBy = this._identityService.GetIdentity();

            var squad = await this._dbContext.Squads.SingleAsync(c => c.Id == model.SquadId);

            var Product = await this._dbContext.Products.SingleAsync(c => c.Id == model.ProductId);

            var entity = SquadProductEntity.Factory.Create(squad, Product, this._datetimeGateway.GetCurrentDateTime(), createdBy);

            this._dbContext.SquadProducts.Add(entity);

            await this._dbContext.SaveChangesAsync();

            result.AddResult("Id", entity.Id);

            return(result);
        }
예제 #14
0
        public async Task <BaseComponentResultRp> DeleteMember(int memberId)
        {
            var result    = new BaseComponentResultRp();
            var createdBy = this._identityGateway.GetIdentity();

            this._dbContext.ChangeTracker.AutoDetectChangesEnabled = true;

            var member = await this._dbContext.Members.SingleAsync(c => c.Id == memberId);

            if (member == null)
            {
                result.AddNotFound($"The Resource {memberId} doesn't exists.");
                return(result);
            }

            this._dbContext.Members.Remove(member);
            await this._dbContext.SaveChangesAsync();

            return(result);
        }
예제 #15
0
        /// <summary>
        /// Update appsetting
        /// </summary>
        /// <param name="model">AppSetting Model</param>
        /// <returns></returns>
        public async Task <BaseComponentResultRp> UpdateAppSetting(string key, AppSettingPutRp model)
        {
            var result     = new BaseComponentResultRp();
            var appSetting = await this._appSettingRepository.GetAppSettingByKey(key);

            if (appSetting == null)
            {
                result.AddNotFound($"The Key {key} doesn't exists.");
                return(result);
            }

            appSetting.Value     = model.Value;
            appSetting.UpdatedBy = this._identityService.GetIdentity();
            appSetting.UpdatedOn = DateTime.UtcNow;

            this._appSettingRepository.Update(appSetting);

            await this._appSettingRepository.SaveChanges();

            return(result);
        }
예제 #16
0
        public async Task RegisterSquad(SquadFeaturePostRp model)
        {
            var result = new BaseComponentResultRp();

            var createdBy = this._identityGateway.GetIdentity();


            var target = await this._dbContext.SquadFeatures.Where(c => c.SquadId == model.SquadId &&
                                                                   c.FeatureId == model.FeatureId).SingleOrDefaultAsync();

            if (target == null)
            {
                var squad = await this._dbContext.Squads.SingleAsync(c => c.Id == model.SquadId);

                var feature = await this._dbContext.Features.SingleAsync(c => c.Id == model.FeatureId);

                var entity = SquadFeatureEntity.Factory.Create(squad, feature, this._datetimeGateway.GetCurrentDateTime(), createdBy);
                this._dbContext.SquadFeatures.Add(entity);
                await this._dbContext.SaveChangesAsync();
            }
        }
예제 #17
0
        /// <summary>
        /// Delete Product
        /// </summary>
        /// <param name="key">Product Id</param>
        /// <returns></returns>
        public async Task DeleteProduct(int id)
        {
            var result     = new BaseComponentResultRp();
            var modifiedBy = this._identityGateway.GetIdentity();

            var product = await this._dbContext.Products
                          .Include(c => c.Journeys)
                          .Include(c => c.Features)
                          .Include(c => c.Incidents)
                          .Include(c => c.Sources)
                          .SingleAsync(c => c.Id == id);

            var squads = await this._dbContext.Squads
                         .Include(c => c.FeatureMaps)
                         .Where(c => c.CustomerId == product.CustomerId).ToListAsync();



            if (product != null)
            {
                foreach (var journey in product.Journeys.Select(c => c.Id.Value).ToList())
                {
                    await this._dbContext.RemoveJourney(journey);
                }

                await this._dbContext.SaveChangesAsync();

                foreach (var feature in product.Features.Select(c => c.Id.Value).ToList())
                {
                    await this._dbContext.RemoveFeature(feature);
                }

                await this._dbContext.SaveChangesAsync();

                this._dbContext.Products.Remove(product);
                await this._dbContext.SaveChangesAsync();
            }
        }
예제 #18
0
        /// <summary>
        /// Create a new Feature
        /// </summary>
        /// <param name="model">Feature Model</param>
        /// <returns></returns>
        public async Task <FeatureGetListRp> CreateFeature(FeaturePostRp model)
        {
            var result    = new BaseComponentResultRp();
            var createdBy = this._identityGateway.GetIdentity();

            var retryPolicy = Policy.Handle <DbUpdateException>()
                              .WaitAndRetryAsync(this._configuration.DefaultRetryAttempts,
                                                 i => this._configuration.DefaultPauseBetweenFails);

            return(await retryPolicy.ExecuteAsync(async() =>
            {
                var entity = await this._dbContext.Features.Where(c => c.ProductId == model.ProductId && c.Name == model.Name).SingleOrDefaultAsync();
                if (entity == null)
                {
                    var product = await this._dbContext.Products.SingleAsync(c => c.Id == model.ProductId);
                    entity = FeatureEntity.Factory.Create(model.Name, this._datetimeGateway.GetCurrentDateTime(), createdBy, product);
                    await this._dbContext.AddAsync(entity);
                    await this._dbContext.SaveChangesAsync();
                }

                return this._mapper.Map <FeatureGetListRp>(entity);
            }));
        }
예제 #19
0
        /// <summary>
        /// Create a new appsetting
        /// </summary>
        /// <param name="model">AppSetting Model</param>
        /// <returns></returns>
        public async Task <BaseComponentResultRp> CreateAppSetting(AppSettingPostRp model)
        {
            var result    = new BaseComponentResultRp();
            var createdBy = this._identityService.GetIdentity();

            var appSetting = AppSettingEntity.Factory.Create(model.Key, model.Value, true, createdBy);

            var entity = await this._appSettingRepository.GetAppSettingByKey(model.Key);

            if (entity != null)
            {
                result.AddConflict($"The Key {model.Key} has already been taken.");
                return(result);
            }

            this._appSettingRepository.Add(appSetting);

            await this._appSettingRepository.SaveChanges();

            result.AddResult("Key", appSetting.Key);

            return(result);
        }
예제 #20
0
        /// <summary>
        /// Create a new appsetting
        /// </summary>
        /// <param name="model">AppSetting Model</param>
        /// <returns></returns>
        public async Task <BaseComponentResultRp> CreateAppSetting(AppSettingPostRp model)
        {
            var result    = new BaseComponentResultRp();
            var createdBy = this._identityGateway.GetIdentity();

            var appSetting = AppSettingEntity.Factory.Create(model.Key, model.Value, true, DateTime.UtcNow, createdBy);

            var entity = await this._dbContext.AppSettings.FirstOrDefaultAsync(c => c.Key.Equals(model.Key));

            if (entity != null)
            {
                result.AddConflict($"The Key {model.Key} has already been taken.");
                return(result);
            }

            await this._dbContext.AddAsync(appSetting);

            await this._dbContext.SaveChangesAsync();

            result.AddResult("Key", appSetting.Key);

            return(result);
        }