Exemplo n.º 1
0
        public void ChangeRole_ChangeUserRole_Failure()
        {
            int[]             user = new int[] { 1, 2, 61 };
            byte              role = 3;
            ChangeRoleRequest req  = new ChangeRoleRequest();

            req.RoleID = role;
            req.UserID = user;
            mockUserRepository.Setup(cr => cr.ChangeRole(It.IsAny <short>(), It.IsAny <int[]>())).Verifiable();
            ChangeRoleResponse res = userService.ChangeRole(req);

            mockRepository.VerifyAll();
            Assert.AreEqual(res.Exception, null);
        }
        public HttpResponseMessage ChangeRole([FromBody] ChangeRoleRequest request)
        {
            var response = new ChangeRoleResponse();

            try
            {
                var token = Token.Get(request.Token);
                if (token == null)
                {
                    response.IsTokenTimeout = true;
                }
                else
                {
                    if (AccountBUS.CheckRole3(token.MaNV))
                    {
                        response.Data = true;
                        if (request.IsUp)
                        {
                            var temp = NhanVienRepository.GetInstance().GetUserById(token.MaNV);
                            if (temp != null)
                            {
                                token.CapPQ = 3;
                                token.MaCN  = temp.MaCN;
                            }
                            else
                            {
                                response.IsError = true;
                            }
                        }
                        else
                        {
                            token.CapPQ = 2;
                            token.MaCN  = request.AgencyId;
                        }
                    }
                }
            }
            catch
            {
                response.IsError = true;
            }
            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }