Beispiel #1
0
        public ActionResult CreateUser(UserCreateDto userCreateDto)
        {
            int idAdress;

            Address        addressModel   = _mapper.Map <Address>(userCreateDto);
            User           userModel      = _mapper.Map <User>(userCreateDto);
            AddressReadDto addressReadDto = _mapper.Map <AddressReadDto>(addressModel);

            if (_repositoryPerson.GetUserLogin(userModel.Username) == null)
            {
                try
                {
                    idAdress            = _repositoryAddress.getAddressByValue(addressReadDto);
                    userModel.IdAddress = idAdress;
                }
                catch (Exception)
                {
                    _repositoryAddress.createAddress(addressModel);
                    _repositoryAddress.saveChange();
                    userModel.IdAddress = addressModel.IdAddress;
                }
                userModel.Password = simpleHash.Compute(userModel.Password);
                _repositoryPerson.createPerson(userModel);
                _repositoryPerson.saveChange();
            }
            else
            {
                return(StatusCode(StatusCodes.Status200OK, new { status = "Error", message = "Login is already used" }));
            }

            return(StatusCode(StatusCodes.Status200OK, new { status = "success", message = "success" }));
        }