public void given_information() { representation = Builder <AppSettingPostRp> .CreateNew() .With(x => x.Key = $"{Guid.NewGuid()}") .With(x => x.Value = $"{Guid.NewGuid()}") .Build(); }
public async Task <IActionResult> Post([FromBody] AppSettingPostRp resource) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } await this._appSettingService.CreateAppSetting(resource); if (this._businnesManagerService.HasConflicts()) { return(this.Conflict(this._businnesManagerService.GetConflicts())); } return(this.Ok()); }
public async Task <IActionResult> Post([FromBody] AppSettingPostRp resource) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var response = await this._appSettingComponent.CreateAppSetting(resource); if (response.HasConflicts()) { return(this.Conflict(response.GetConflicts())); } return(this.Ok()); }
public async Task CreateAppSetting(AppSettingPostRp resource) { var createdBy = this._identityService.GetUserId(); var appSetting = AppSetting.Factory.Create(resource.Id, resource.Value, createdBy); var entity = await this._appSettingDataService.GetById(resource.Id); if (entity != null) { await _businessManagerService.AddConflict($"The Id {resource.Id} has already been taken."); return; } await this._appSettingDataService.Add(appSetting); await this._appSettingDataService.SaveChanges(); await _businessManagerService.AddResult("Key", appSetting.Id); }
/// <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); }
/// <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); }