示例#1
0
        public IHttpActionResult CreateStudent(StudentDto studentDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var student = Mapper.Map <StudentDto, Student1>(studentDto);

            context.Students.Add(student);
            context.SaveChanges();

            studentDto.Id = student.Id;
            return(Created(new Uri(Request.RequestUri + "/" + student.Id), studentDto));
        }
示例#2
0
 public ActionResult Create(Student1 student)
 {
     if (ModelState.IsValid)
     {
         context.Student1s.Add(student);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(student));
 }