コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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)));
        }
コード例 #4
0
        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);
        }