public IActionResult Register([FromBody] AdministratorModel userModel)
        {
            // map dto to entity
            var user  = _iMapper.Map <Administrator>(userModel);
            var count = 1;

            try
            {
                // save
                var result = _iAdministratorService.Create(user, userModel.Password);
                if (result != null)
                {
                    return(Output(new LoginResponse
                    {
                        email = user.Email,
                    }, count));
                }
                throw new Exception("注册失败!");
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
Esempio n. 2
0
        public ActionResult Create(AdministratorEditModel editModel)
        {
            if (editModel.IsValid() == false)
            {
                Response.StatusCode = 500;
                return(PartialView("_ValidationErrorSummary", new ValidationErrorSummaryViewModel(editModel.GetValidationErrors())));
            }

            AdministratorListItemViewModel viewModel = _administratorService.Create(editModel);

            return(PartialView("_AdministratorTableRow", viewModel));
        }
        public async Task <ActionResult <AdministratorDetail_AdministratorDTO> > Create([FromBody] AdministratorDetail_AdministratorDTO AdministratorDetail_AdministratorDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new MessageException(ModelState);
            }

            Administrator Administrator = ConvertDTOToEntity(AdministratorDetail_AdministratorDTO);

            Administrator = await AdministratorService.Create(Administrator);

            AdministratorDetail_AdministratorDTO = new AdministratorDetail_AdministratorDTO(Administrator);
            if (Administrator.IsValidated)
            {
                return(AdministratorDetail_AdministratorDTO);
            }
            else
            {
                return(BadRequest(AdministratorDetail_AdministratorDTO));
            }
        }