// POST api/values public void Post([FromBody] ResourceDto value) { if (ModelState.IsValid) { _service.Create(value); } }
public void CreateTest_Exception() { // Arrange ResourceService target = new ResourceService(_exceptionRepository, _mockLogger, _mapper); Resource expected = _mockdata.NewResource(); // Act Resource actual = target.Create(expected); // Assert Assert.IsTrue(target.HasError); }
public void CreateTest() { // Arrange ResourceService target = new ResourceService(_repository, _mockLogger, _mapper); Resource expected = _mockdata.NewResource(); // Act Resource actual = target.Create(expected); // Assert Assert.IsFalse(actual.Id == 0); Assert.IsFalse(target.HasError); }
public IActionResult Post(WResource res) { try { if (string.IsNullOrEmpty(res.Id)) { _resourceService.Create(res); } else { _resourceService.Update(res); } } catch (Exception ex) { return(this.BadRequest()); } return(this.Ok()); }
private int addResources(int articleID, HttpPostedFileBase[] files) { int rows_affected = 0; foreach (var file in files) { if (file != null && file.ContentLength > 0) { var filename = Path.GetFileName(file.FileName); var res = new ResourceViewModel { article_id = articleID, path = filename, type = file.ContentType }; var directory = Path.Combine(Server.MapPath("~/resources"), "resource_" + articleID); Directory.CreateDirectory(directory); var path_file = directory + "/" + filename; file.SaveAs(path_file); rows_affected += _resourceService.Create(res); } } return(rows_affected); }
// [ValidateAntiForgeryToken] public ActionResult <Resource> Create() { _logger.Log(LogLevel.Information, "Creating resource"); Resource resource = null; try { if (resource == null) { resource = new Resource { ResourceTitle = "Test Overflow", ResourceDescription = "This is Create test", Uri = "www.testoverflow.com", UpVote = 11, DownVote = 10 }; } // TODO: Add insert logic here _resourceService.Create(resource); return(Redirect("/")); //return CreatedAtRoute("GetResource", new { id = resource.Id.ToString() }, resource); } catch { return(Content("Insert Record Error")); } }
public void Create(Resource resource) { _resourceService.Create(resource); }