public void SaveProject() { //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} try { using (var bdContext = new HOCContext()) { //_context.Projects.Add(projects); Projects P1 = new Projects(); P1.Name = "Test2"; P1.Description = "Description"; P1.CreatedBy = 1; P1.ModifiedBy = 1; P1.ModifiedOn = DateTime.Today; P1.Stage = 0; bdContext.Projects.Add(P1); bdContext.SaveChanges(); //return CreatedAtAction("GetProjects", new { id = P1.Id }, projects); } } catch (Exception ex) { } }
public async Task <IActionResult> PostProjects([FromBody] Projects projects) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var bdContext = new HOCContext()) { _context.Projects.Add(projects); Projects P1 = new Projects(); P1.Name = "Test2"; P1.Description = "Description"; P1.CreatedBy = 1; P1.ModifiedBy = 1; P1.ModifiedOn = DateTime.Today; P1.Stage = 0; bdContext.Projects.Add(P1); bdContext.SaveChanges(); } try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (ProjectsExists(projects.Id)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetProjects", new { id = projects.Id }, projects)); }