Ejemplo n.º 1
0
        public HttpResponseMessage GetActiveTheme(string ipAddress)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,ThemeV1Controller,GetActiveTheme,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");

            ErrorMessage error;
            string       message;

            var posId = _loginManager.Authenticate(ipAddress, out message, out error);

            if (!string.IsNullOrEmpty(error.MessageStyle.Message))
            {
                _performancelog.Debug($"End,ThemeV1Controller,GetActiveTheme,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
                return(Request.CreateResponse(
                           error.StatusCode,
                           new InvalidLoginReponseModel
                {
                    Error = error.MessageStyle,
                    ShutDownPOS = error.ShutDownPos
                }));
            }

            if (posId == 0)
            {
                _performancelog.Debug($"End,ThemeV1Controller,GetActiveTheme,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
                var store  = CacheManager.GetStoreInfo();
                var offSet = store?.OffSet ?? 0;
                return(Request.CreateResponse(
                           HttpStatusCode.Unauthorized,
                           new InvalidLoginReponseModel
                {
                    Error = new MessageStyle {
                        Message = _resourceManager.GetResString(8198, offSet)
                    },
                    ShutDownPOS = error.ShutDownPos
                }));
            }

            var theme = _themeManager.GetActiveTheme();

            if (theme != null)
            {
                return(Request.CreateResponse
                           (HttpStatusCode.OK,
                           new ThemeModel
                {
                    BackgroundColor1Light = theme.Data.FirstOrDefault(x => x.Name == "BackgroundColor1Light")?.ColorCode,
                    BackgroundColor1Dark = theme.Data.FirstOrDefault(x => x.Name == "BackgroundColor1Dark")?.ColorCode,
                    BackgroundColor2 = theme.Data.FirstOrDefault(x => x.Name == "BackgroundColor2")?.ColorCode,
                    ButtonFooterConfirmationColor = theme.Data.FirstOrDefault(x => x.Name == "ButtonFooterConfirmationColor")?.ColorCode,
                    ButtonFooterWarningColor = theme.Data.FirstOrDefault(x => x.Name == "ButtonFooterWarningColor")?.ColorCode,
                    HeaderBackgroundColor = theme.Data.FirstOrDefault(x => x.Name == "ButtonBackgroundColor")?.ColorCode,
                    HeaderForegroundColor = theme.Data.FirstOrDefault(x => x.Name == "ButtonForegroundColor")?.ColorCode,
                    ButtonFooterColor = theme.Data.FirstOrDefault(x => x.Name == "ButtonFooterColor")?.ColorCode,
                    LabelTextForegroundColor = theme.Data.FirstOrDefault(x => x.Name == "LabelTextForegroundColor")?.ColorCode
                }));
            }

            return(Request.CreateResponse(
                       HttpStatusCode.NotFound,
                       new ErrorResponse
            {
                Error = new MessageStyle {
                    Message = "There are no themes defined!"
                }
            }));
        }