public async Task <Devkit> AddAsync(Devkit devkit) { _dkContext.Set <Devkit>().Add(devkit); await _dkContext.SaveChangesAsync(); return(devkit); }
public async Task <IActionResult> PutDevkit([FromRoute] int id, [FromBody] Devkit devkit) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != devkit.DevkitID) { return(BadRequest()); } //_context.Entry(devkit).State = EntityState.Modified; try { await _devkitService.UpdateAsync(devkit, id); //await _devkitService.AddAsync(devkit); // await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DevkitExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Should_return_OkObjectResult_with_a_list_devkits() { // Arrange var expectedDevkits = new Devkit[] { new Devkit { Name = "Test clan 1" }, new Devkit { Name = "Test clan 2" }, new Devkit { Name = "Test clan 3" } }; DevkitServiceMock .Setup(x => x.GetDevkits()) .Returns(expectedDevkits); // Mocked the ReadAllAsync() method // Act var result = ControllerUnderTest.GetDevkits(); // Assert // var okResult = Assert.IsType<IEnumerable<Devkit>>(result); Assert.Same(expectedDevkits, result); //Assert.NotSame(expectedDevkits, result); }
public async Task <IActionResult> PostDevkit([FromBody] Devkit devkit) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //_context.Devkits.Add(devkit); //await _context.SaveChangesAsync(); await _devkitService.AddAsync(devkit); return(CreatedAtAction("PostDevkit", new { id = devkit.DevkitID }, devkit)); }
public async Task <ResultSingle <Devkit> > QueryDevkitAsync(Devkit devkit, bool doCache = false, bool throwIfError = true) { ResultSingle <Devkit> result = await ResultSingleUI <Devkit> .WaitForObjectAsync( throwIfError, devkit, new CachedHttpRequest <Devkit, ResultSingle <Devkit> >( Backend.QueryAsync), doCache); if (result.Code >= 0) { result.Data.Payload.CopyTo(devkit); } return(result); }
public async Task <Devkit> UpdateAsync(Devkit devkit, object key) { if (devkit == null) { return(null); } Devkit exist = await _dkContext.Set <Devkit>().FindAsync(key); if (exist != null) { _dkContext.Entry(exist).CurrentValues.SetValues(devkit); await _dkContext.SaveChangesAsync(); } return(exist); }
async private void ButtonAppDownload_ClickedAsync(object sender, EventArgs e) { IsServiceActive = true; try { var folder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var filePath = Path.Combine(folder, string.Format("{0}.devkit", AppViewModel.EditApp.Tag)); var alreadyExist = File.Exists(filePath); if (alreadyExist) { var yes = await DisplayAlert("Nester", "A downloaded Devkit already exists here. Overwrite? \n" + filePath, "Yes", "No"); if (!yes) { return; } File.Delete(filePath); } Devkit devkit = new Devkit(); devkit.OwnedBy = AppViewModel.ContactViewModel.OwnerContact; await AppViewModel.DeploymentViewModel.QueryDevkitAsync(devkit); File.WriteAllText(filePath, devkit.Script); await DisplayAlert("Nester", "The Devkit was emailed. A copy was downloaded here:\n" + filePath, "OK"); Device.OpenUri(new Uri("file://" + folder.Replace("\\", "/"))); } catch (Exception ex) { await ErrorHandler.ExceptionAsync(this, ex); } IsServiceActive = false; }
public Devkit Add(Devkit devkit) { _dkContext.Set <Devkit>().Add(devkit); _dkContext.SaveChanges(); return(devkit); }
public async Task <int> DeleteAsync(Devkit devkit) { _dkContext.Set <Devkit>().Remove(devkit); return(await _dkContext.SaveChangesAsync()); }