public async Task <IActionResult> Create(UserTypeAddDto userTypeAddDto) { if (ModelState.IsValid) { UserType addUser = _mapper.Map <UserType>(userTypeAddDto); await _userTypeManager.AddAsync(addUser); return(RedirectToAction("Index")); } return(View(userTypeAddDto)); }
public async Task <IActionResult> AddUserType(UserTypeAddDto newUserType) { ServiceResponse <List <UserTypeGetDto> > response = await _userTypeService.AddUserType(newUserType); if (response.Data == null) { return(NotFound(response)); } return(Ok(response)); }
public async Task <IActionResult> Add(UserTypeAddDto newUserType) { if (!ModelState.IsValid) { return(BadRequest()); } var userType = _mapper.Map <UserType>(newUserType); var userTypeResult = await _userTypeService.Add(userType); if (userTypeResult == null) { return(BadRequest()); } return(Ok(_mapper.Map <UserTypeResultDto>(userTypeResult))); }
public async Task <ServiceResponse <List <UserTypeGetDto> > > AddUserType(UserTypeAddDto newUserType) { ServiceResponse <List <UserTypeGetDto> > serviceResponse = new ServiceResponse <List <UserTypeGetDto> >(); UserType userType = _mapper.Map <UserType>(newUserType); try { await _context.UserTypes.AddAsync(userType); await _context.SaveChangesAsync(); serviceResponse.Data = (_context.UserTypes.Select(u => _mapper.Map <UserTypeGetDto>(u))).ToList(); } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = ex.Message; } return(serviceResponse); }