public async Task <IActionResult> Put(int id, [FromBody] ToggleViewModel toggleViewModel) { try { if (id <= 0 || toggleViewModel == null) { return(BadRequest()); } var toggle = await _toggleServices.GetToggleByIdAsync(id); if (toggle == null) { return(NotFound($"Toggle Id {id} does not exists.")); } toggle.Enable = toggleViewModel.Value; toggle.Name = toggleViewModel.Name; var toggleUpdated = await _toggleServices.UpdateToggleAsync(toggle); return(Ok($"Toggle Updated. id = { toggleUpdated.Id }")); } catch (Exception) { return(NotFound($"Toggle {id} does not exist")); } }
public async Task <IActionResult> Post(int applicationId, string version, [FromBody] ToggleViewModel toggleViewModel) { try { if (applicationId <= 0 || string.IsNullOrWhiteSpace(version) || toggleViewModel == null) { return(BadRequest($"Invalid parameters")); } if (await _applicationServices.GetApplicationByIdAsync(applicationId) == null) { return(NotFound($"ApplicationId {applicationId} does not exists.")); } var toggleSaved = await _toggleServices .AddToggleAsync(new Toggle { ApplicationId = applicationId, Version = version, Name = toggleViewModel.Name, Enable = toggleViewModel.Value }); return(Ok($"New Toggle registered. id = { toggleSaved.Id }")); } catch (Exception) { return(NotFound($"Error: New Toggle {toggleViewModel.Name} not registered")); } }
protected override void Init() { BindingContext = new ToggleViewModel(); }