Exemplo n.º 1
0
 public int InsertStudentMarks(CreateStudentMark student)
 {
     using (var conn = new SqlConnection(_connectionStringHolder.Value))
     {
         //conn.Open(); //qq does this need to be opened? No.
         var affectedRows = conn.Execute("Insert into StudentMarks (Name, Subject, Marks) values (@Name, @subject, @Marks)", new { Name = student.Name, Subject = student.Subject, Marks = student.Marks });
         //conn.Close();
         return(affectedRows);
     }
 }
Exemplo n.º 2
0
        [HttpPost("api/FiddlerExAddStudentMarksPost")]  // [HttpGet("FiddlerExAddStudentMarksPost")]  doesn't work
        //[ActionName("Post")] //qq is this attribute req'd
        //[ValidateAntiForgeryToken]
        public ActionResult FiddlerExAddStudentMarksPost([Bind("Name, Subject, Marks")] CreateStudentMark sm)
        {
            var x = _fiddlerRepository.InsertStudentMarks(sm);

            if (x != 0)  //(x != null)
            {
                //return Ok(x);
                //return Created(new Uri("/Home/Index/testPathOnly", UriKind.Relative), newItem); //the path is returned in the "Location" header for this item (its value can be nonsense).
                return(CreatedAtAction("FiddlerExAddStudentMarksPost", sm)); //the full path for this action is returned in the "Location" header for this item (must be valid action method name).
            }

            //return NotFound(new { Message = $"Something went wrong!!?." });
            return(BadRequest(new { Message = $"Something went wrong!!?." }));
        }