public TMSLevel Add(TMSLevelCreateViewModel Vm) { var entity = _mapper.Map <TMSLevelCreateViewModel, TMSLevel>(Vm); _itmsLevelRepository.Add(entity); SaveChanges(); return(entity); }
public IActionResult Add([FromBody] TMSLevelCreateViewModel Vm) { if (!ModelState.IsValid) { var allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(new GenericResult(false, allErrors))); } else { try { _tmsLevelService.Add(Vm); return(new OkObjectResult(new GenericResult(true, "Add success!!!"))); } catch (Exception ex) { return(new OkObjectResult(new GenericResult(false, ex.Message))); } } }