예제 #1
0
        public void UpdateUserTest()
        {
            UserCRUD userService = new UserCRUD(new TestDataRepository());

            userService.AddUser(11, "Max", "Verstappen");

            Assert.IsTrue(userService.UpdateLastName(11, "Caulfield"));
            Assert.AreEqual(userService.GetUser(11).LastName, "Caulfield");

            Assert.IsTrue(userService.UpdateFirstName(11, "Timothy"));
            Assert.AreEqual(userService.GetUser(11).FirstName, "Timothy");

            userService.DeleteUser(11);
        }
        public bool IsUserValid(string email, string password, out string statusMessage)
        {
            bool isValid = false;

            statusMessage = "User is either locked or Inactive to perform any action";
            UserCRUD userCRUD = new UserCRUD();
            var      user     = userCRUD.GetUser(email, password);

            if (user != null)
            {
                if (user.is_active == true)
                {
                    if ((user.is_locked != true))
                    {
                        statusMessage = string.Empty;
                        isValid       = true;
                    }
                }
            }
            else
            {
                statusMessage = HttpStatusCode.Unauthorized.ToString();
            }

            return(isValid);
        }
예제 #3
0
        public void GetUserTest()
        {
            UserCRUD userService = new UserCRUD(new TestDataRepository());

            userService.AddUser(88, "Chloe", "Price");

            Assert.AreEqual(userService.GetUser(88).FirstName, "Chloe");

            userService.DeleteUser(88);
        }
        public IActionResult VerifyOTP(VerifyOTPReq req)
        {
            VerifyOTPResp resp = new VerifyOTPResp();

            try
            {
                if (RequestValidator.VerifyOTP(req))
                {
                    if (UserCRUD.IsValidUser(req.user_id))
                    {
                        if (DeviceCRUD.VerifyOTP(req.device_id, req.user_id, Convert.ToString(req.otp)) || req.otp == 1111)
                        {
                            var user = UserCRUD.GetUser(req.user_id);
                            // DeviceCRUD.NulifyOTP(req.device_id, req.user_id, Convert.ToString(req.otp));
                            RegisteredDevice device = DeviceCRUD.GetDevice(req.device_id);

                            resp.name           = user.Name;
                            resp.status_code    = Ok().StatusCode;
                            resp.status_message = StatusMessage.Success;
                            resp.token          = JwtToken.GenerateJwtToken(device);
                        }
                        else
                        {
                            resp.status_code    = Unauthorized().StatusCode;
                            resp.status_message = StatusMessage.UnAuthorised;
                        }
                    }
                    else
                    {
                        resp.status_code    = BadRequest().StatusCode;
                        resp.status_message = StatusMessage.BadRequest;
                    }
                }
                else
                {
                    resp.status_code    = BadRequest().StatusCode;
                    resp.status_message = StatusMessage.BadRequest;
                }
            }
            catch (Exception es)
            {
                resp.status_code    = 500;
                resp.status_message = StatusMessage.InternalServerError;
            }

            return(Ok(resp));
        }
        public UserResponse Profile(BaseResquest req)
        {
            UserResponse resp = new UserResponse();

            try
            {
                if (ValidateRequest.Profile(req))
                {
                    UserCRUD userCRUD = new UserCRUD();
                    var      email    = JWTService.ValidateToken(req.Token);
                    if (!string.IsNullOrEmpty(email))
                    {
                        var user = userCRUD.GetUser(email);
                        if (user != null)
                        {
                            resp.User          = user;
                            resp.User.password = null;
                            resp.StatusCode    = HttpStatusCode.OK;
                            resp.StatusMessage = HttpStatusCode.OK.ToString();
                        }
                        else
                        {
                            resp.StatusCode    = HttpStatusCode.NotFound;
                            resp.StatusMessage = HttpStatusCode.NotFound.ToString();
                        }
                    }
                    else
                    {
                        resp.StatusCode    = HttpStatusCode.Unauthorized;
                        resp.StatusMessage = HttpStatusCode.Unauthorized.ToString();
                    }
                }
                else
                {
                    resp.StatusCode    = HttpStatusCode.BadRequest;
                    resp.StatusMessage = HttpStatusCode.BadRequest.ToString();
                }
            }
            catch (Exception es)
            {
                resp.StatusCode    = HttpStatusCode.InternalServerError;
                resp.StatusMessage = HttpStatusCode.InternalServerError.ToString();
            }
            return(resp);
        }
        public IActionResult TeamList(BaseRequest req)
        {
            EscalationUserResp resp = new EscalationUserResp();

            try
            {
                if (RequestValidator.TeamList(req))
                {
                    if (req.user_id == JwtToken.GetUserID(req.token))
                    {
                        var user  = UserCRUD.GetUser(req.user_id);
                        int?scale = UserCRUD.GetUserRole(req.user_id).Scale;

                        resp.status_code    = Ok().StatusCode;
                        resp.status_message = StatusMessage.Success;
                        resp.UserList       = UserCRUD.GetEscalationUserList(user.Id, user.CompanyId, scale ?? 0, req.feedback_id);
                    }
                    else
                    {
                        resp.status_code    = Unauthorized().StatusCode;
                        resp.status_message = StatusMessage.UnAuthorised;
                    }
                }
                else
                {
                    resp.status_code    = BadRequest().StatusCode;
                    resp.status_message = StatusMessage.BadRequest;
                }
            }
            catch (Exception es)
            {
                resp.status_code    = 500;
                resp.status_message = StatusMessage.InternalServerError;
            }

            return(Ok(resp));
        }