public IActionResult Post([FromBody] LoginCreateDto loginCreateDto)
        {
            if (loginCreateDto == null)
            {
                return(BadRequest());
            }

            var login = Mapper.Map <Login>(loginCreateDto);
            var user  = Mapper.Map <User>(loginCreateDto);

            //if (!_loginRepository.CompanyExists(login.Company))
            //{
            //    user.Department = Default_Department;
            //    user.Position = Default_Position;
            //}

            _loginRepository.AddLogin(login);
            _unitOfWorkCompany.ChangeDatabase(login.Company);
            _userRepository.AddUser(user);

            var userinfo = Mapper.Map <UserInfoDto>(loginCreateDto);

            if (_unitOfWorkEntrance.Save() & _unitOfWorkCompany.Save())
            {
                return(CreatedAtRoute("GetUser", new { username = user.UserName }, userinfo));
            }
            else
            {
                return(StatusCode(500, "将用户信息存入数据库时出错"));
            }
        }
 //public void AddLogin([FromBody] Login login) => loginRepository.Add(login);
 public ActionResult <LoginDto> PostLogin(LoginDto loginDto)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Invalid Data"));
     }
     loginRepository.AddLogin(loginDto);
     return(Ok("Added Successfully."));
 }
 public string AddLogin(Login obj)
 {
     List<Login> myList = _loginrepo.GetAllRepo();
     foreach (var temp in myList)
     {
         if (obj.email == temp.email)
         {
             return "not success";
         }
     }
    _loginrepo.AddLogin(obj);
   return "success";
 }
        public async Task <ActionResult <Login> > AddLogin([FromBody] Login newLogin)
        {
            try
            {
                var result = await _loginRepository.AddLogin(newLogin);

                if (result != null)
                {
                    return(Ok(result));
                }

                _logger.Log(LogLevel.Warning, $"Couldn't add login {newLogin.LogIn}");
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, $"Error while call AddLogin - {ex}");
                return(BadRequest(ex.Message));
            }
        }
 public async Task <ActionResult> Post([FromBody] Logins login)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Not a valid model..."));
     }
     try
     {
         if (login == null)
         {
             return(BadRequest());
         }
         await _loginRepository.AddLogin(login);
     }
     catch (Exception)
     {
         return(BadRequest("Not a valid model."));
     }
     return(Created(new Uri("/api/Libary", UriKind.Relative), login));
 }
Beispiel #6
0
        public void AddLogin(LoginVM login)
        {
            var loginEM = mapper.ConvertTo <LoginEM>(login);

            loginRepository.AddLogin(loginEM);
        }