public IActionResult CreateSource([FromBody] string name, [FromBody] string environment, [FromBody] string encoding) { if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(environment) || string.IsNullOrEmpty(encoding)) { return(BadRequest()); } if (!AllowedSourceEncoding.Contains(environment)) { return(BadRequest($"{environment} is not a valid environment.")); } if (!AllowedSourceEncoding.Contains(encoding)) { return(BadRequest($"{encoding} is not a valid encoding.")); } var newSource = new Source { Id = Guid.NewGuid().ToString(), Name = name, Environment = environment, Encoding = encoding, Created = DateTime.UtcNow, Updated = DateTime.UtcNow }; _database.Sources.Add(newSource); _database.SaveChanges(); return(Json(newSource)); }
public IActionResult UpdateSource(string sourceId, [FromBody] string name, [FromBody] string environment, [FromBody] string encoding) { if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(environment) || string.IsNullOrEmpty(encoding)) { return(BadRequest()); } if (!AllowedSourceEncoding.Contains(environment)) { return(BadRequest($"{environment} is not a valid environment.")); } if (!AllowedSourceEncoding.Contains(encoding)) { return(BadRequest($"{encoding} is not a valid encoding.")); } var sourceToUpdate = _database.Sources.Find(sourceId); if (sourceToUpdate == null) { return(NotFound("Source could not be found.")); } sourceToUpdate.Name = name; sourceToUpdate.Environment = environment; sourceToUpdate.Encoding = encoding; sourceToUpdate.Updated = DateTime.UtcNow; _database.SaveChanges(); return(Json(sourceToUpdate)); }