Exemple #1
0
        public async Task <IActionResult> CreateUser([FromBody] Models.CreateUserRequest rUser)
        {
            Entities.User user      = null;
            var           isCreated = false;

            try
            {
                user = _mapper.Map <Entities.User>(rUser);

                user.Password = "******";
                user.Fullname = "";
                isCreated     = await _userBL.CreateUser(user);

                return(Ok(new { messsage = MessageConstant.INSERT_SUCCESS }));
            }
            catch (DuplicatedUsernameException e)
            {
                return(BadRequest(new { message = e.Message }));
            }
            catch (Exception e)
            {
                if (isCreated)
                {
                    await _userBL.RemoveByIdAsync(user.UserId);
                }
                return(BadRequest(new { message = e.Message }));
            }
        }
Exemple #2
0
        public async Task <IActionResult> CreatePremises()
        {
            try
            {
                Entities.User user = new Entities.User();

                user = new Entities.User()
                {
                    Username   = "******",
                    Email      = "*****@*****.**",
                    Fullname   = "Provider 2",
                    RoleId     = 2,
                    PremisesId = 1
                };
                user.Password = "******";
                await _userBL.CreateUser(user);

                return(Ok(new { messsage = MessageConstant.INSERT_SUCCESS }));
            }
            catch (DuplicatedUsernameException e)
            {
                return(BadRequest(new { message = e.Message }));
            }
            catch (Exception e)
            {
                return(BadRequest(new { message = e.Message }));
            }
        }
Exemple #3
0
        public async Task <Models.CreateUserReponse> CreateUser([FromBody] Models.CreateNewUserRequest newUser)
        {
            Entities.User user = new Entities.User()
            {
                Username = newUser.Username, Password = newUser.Password, RoleId = newUser.RoleId, IsActive = true
            };
            await _bl.CreateUser(user);

            var reponseModel = new Models.CreateUserReponse()
            {
                UserId = user.UserId
            };

            return(reponseModel);
        }
Exemple #4
0
        public async Task <IActionResult> UpdateProfile(int id, [FromBody] Models.UpdateUserRequest userInfo)
        {
            Entities.User user = null;
            try
            {
                user          = _mapper.Map <Entities.User>(userInfo);
                user.UserId   = id;
                user.Fullname = userInfo.Fullname;
                user.Email    = userInfo.Email;
                user.PhoneNo  = userInfo.PhoneNo;
                await _userBL.UpdateUser(user, id);

                return(Ok("success!!"));
            }
            catch (Exception e)
            {
                return(BadRequest(new { message = e.Message }));
            }
        }
Exemple #5
0
        public async Task <IActionResult> UpdateUser([FromBody] Models.UpdateUserRequest userInfo)
        {
            Entities.User user = null;
            try
            {
                var id = int.Parse(User.Claims.First(c => c.Type == "userID").Value);
                user          = _mapper.Map <Entities.User>(userInfo);
                user.UserId   = id;
                user.Fullname = userInfo.Fullname;
                user.Email    = userInfo.Email;
                user.PhoneNo  = userInfo.PhoneNo;
                await _userBL.UpdateUser(user, id);

                return(Ok("success!!"));
            }
            catch (Exception e)
            {
                return(BadRequest(new { message = e.Message }));
            }
        }
Exemple #6
0
        public async Task <IActionResult> Login([FromBody] Models.LoginRequest login)
        {
            try
            {
                var token = await _userBL.CheckLogin(login);

                Entities.User user = null;
                if (token != null)
                {
                    user = await _userBL.FindByName(login.Username);
                }
                var loginReponse = new Models.UserLoginReponse()
                {
                    User  = _mapper.Map <Models.UserData>(user),
                    Token = token
                };
                return(Ok(new { Data = loginReponse }));
            }
            catch (Exception e)
            {
                return(BadRequest(new { message = e.Message, error = e.StackTrace }));
            }
        }