示例#1
0
 public IActionResult Insert([FromBody] StudentsCreateDTO dto)
 {
     try
     {
         var model = mapper.Map <Students>(dto);
         if (model != null)
         {
             repository.Insert(model);
             var result = repository.SaveChanges();
             if (result)
             {
                 return(Ok());
             }
         }
         return(NotFound());
     }
     catch (System.Exception msg)
     {
         return(NotFound(msg));
     }
 }
示例#2
0
 public IActionResult Update(string id, [FromBody] StudentsCreateDTO dto)
 {
     try
     {
         var isExist = repository.GetById(id);
         if (isExist != null)
         {
             mapper.Map(dto, isExist);
             repository.Update(isExist);
             var result = repository.SaveChanges();
             if (result)
             {
                 return(Ok());
             }
         }
         return(NotFound());
     }
     catch (System.Exception msg)
     {
         return(NotFound(msg));
     }
 }