public async Task <IActionResult> Post(string profile, [FromBody] ConfigRequest request) { int profileId = GetProfileId(profile); if (profileId == 0) { return(this.ErrorObject(400, $@"Profile ""{profile}"" is not found")); } Config config = GetConfig(profileId, request.Key); if (config == null) { config = new Config { Key = request.Key, Value = request.Value, ProfileId = profileId }; _context.Add(config); } else { config.Value = request.Value; _context.Update(config); } await _context.SaveChangesAsync(); return(new ObjectResult(request) { StatusCode = 201 }); }
public async Task <IActionResult> Create([Bind("Path,ServiceId,Name,Id")] LayerRecord layerRecord) { if (ModelState.IsValid) { ConfigContext.Add(layerRecord); await ConfigContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ServiceId"] = new SelectList(ConfigContext.Services, "Id", "Id", layerRecord.ServiceId); return(View(layerRecord)); }
private void CreateSampleTask(ConfigContext dbContext) { var profile = new ConfigProfile() { Name = "Shared" }; dbContext.Add(profile); dbContext.SaveChanges(); var config1 = new Config() { Key = "Database", Value = "mssqldb", ProfileId = 1 }; var config2 = new Config() { Key = "Service", Value = "http://localhost", ProfileId = 1 }; dbContext.Add(config1); dbContext.Add(config2); dbContext.SaveChanges(); }