Ejemplo n.º 1
0
        public HttpResponseMessage GetAllPolicies(int registerNumber)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,PolicyController,GetAllPolicies,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");
            var accessToken = Request.GetFirstHeaderValueOrDefault <string>("authToken");

            if (accessToken == null)
            {
                return(Request.CreateResponse(
                           HttpStatusCode.BadRequest,
                           new ErrorResponse
                {
                    Error = new MessageStyle
                    {
                        Message = Resource.Error,
                        MessageType = MessageType.OkOnly
                    }
                }));
            }

            var userCode = TokenValidator.GetUserCode(accessToken);
            var posId    = TokenValidator.GetPosId(accessToken);

            //delete and initialise a new register by sale initialisation
            CacheManager.DeleteRegister(posId);
            var policies = _policyManager.GetAllPolicies(userCode);

            if (policies == null)
            {
                return(Request.CreateResponse(
                           HttpStatusCode.Unauthorized,
                           new ErrorResponse
                {
                    Error = new MessageStyle
                    {
                        Message = Resource.Error,
                        MessageType = MessageType.OkOnly
                    }
                }));
            }
            var allPolicies = (object)policies;

            _performancelog.Debug($"End,PolicyController,GetAllPolicies,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            return(Request.CreateResponse(HttpStatusCode.OK, allPolicies));
        }