Esempio n. 1
0
        /// <summary>
        /// Method to get user code
        /// </summary>
        /// <param name="userCode">Usercode</param>
        /// <param name="httpResponseMessage">HttpResponse</param>
        /// <returns>True or false</returns>
        private bool GetUserCode(out string userCode, out HttpResponseMessage httpResponseMessage)
        {
            var dateStart = DateTime.Now;

            userCode            = string.Empty;
            httpResponseMessage = null;
            _performancelog.Debug($"Start,KickBackController,GetUserCode,{string.Empty},{dateStart:hh.mm.ss.ffffff}");
            var accessToken = Request.GetFirstHeaderValueOrDefault <string>("authToken");

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

            userCode = TokenValidator.GetUserCode(accessToken);
            _performancelog.Debug($"End,KickBackController,GetUserCode,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            return(false);
        }
Esempio n. 2
0
        public HttpResponseMessage AddStock([FromBody] StockModel stock)
        {
            var dateStart = DateTime.Now;

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

            ErrorMessage error;
            var          accessToken = Request.GetFirstHeaderValueOrDefault <string>("authToken");

            if (accessToken == null)
            {
                return(Request.CreateResponse(
                           HttpStatusCode.BadRequest,
                           new ErrorResponse
                {
                    Error = new MessageStyle {
                        Message = Resource.Error, MessageType = 0
                    }
                }));
            }
            if (stock == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse
                {
                    Error = new MessageStyle
                    {
                        Message = Resource.InvalidInformation,
                        MessageType = MessageType.OkOnly
                    }
                }));
            }
            var userCode  = TokenValidator.GetUserCode(accessToken);
            var stockItem = new StockItem
            {
                Description = stock.Description,
                Price       = stock.RegularPrice,
                StockCode   = stock.StockCode
            };

            _stockManager.AddStockItem(userCode, stockItem, stock.TaxCodes, out error);

            if (!string.IsNullOrEmpty(error.MessageStyle.Message))
            {
                _performancelog.Debug($"End,StockV1Controller,AddStock,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
                return(Request.CreateResponse(error.StatusCode, new ErrorResponse
                {
                    Error = error.MessageStyle
                }));
            }
            _performancelog.Debug($"End,StockV1Controller,AddStock,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            return(Request.CreateResponse(HttpStatusCode.OK, new SuccessReponse
            {
                Success = true
            }));
        }
Esempio n. 3
0
        public HttpResponseMessage SaveMessage([FromBody] MessageModel messageModel)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,MessageController,SaveMessage,{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 = 0
                    }
                }));
            }
            if (messageModel == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse
                {
                    Error = new MessageStyle
                    {
                        Message = Resource.InvalidInformation
                    }
                }));
            }
            var userCode = TokenValidator.GetUserCode(accessToken);
            var message  = new MessageButton
            {
                Message = messageModel.Message,
                Index   = messageModel.Index
            };
            ErrorMessage error;

            _messageManager.SaveMessage(message, messageModel.TillNumber, userCode, out error);

            _performancelog.Debug($"End,MessageController,SaveMessage,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            var response = new SuccessReponse {
                Success = true
            };

            if (string.IsNullOrEmpty(error.MessageStyle.Message))
            {
                return(Request.CreateResponse(HttpStatusCode.OK, response));
            }

            return(Request.CreateResponse(error.StatusCode,
                                          new ErrorResponse
            {
                Error = error.MessageStyle,
            }));
        }
        public HttpResponseMessage AddFuelSaleFromBasket([FromBody] FuelBasketModel model)
        {
            // bool  flag = false;
            //SaleModel s=null;
            WriteUDPData(DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") + "Inside if 550");
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,FuelPumpController,AddPrepay,{string.Empty},{dateStart:hh.mm.ss.ffffff}");

            ErrorMessage error;
            var          accessToken = Request.GetFirstHeaderValueOrDefault <string>("authToken");

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

            var userCode = TokenValidator.GetUserCode(accessToken);

            WriteUDPData(DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") + "Inside 572");
            var sale = _fuelPumpManager.AddFuelSaleFromBasket(model.SaleNumber, model.TillNumber, model.RegisterNumber, model.ActivePump, model.BasketValue, out error);

            WriteUDPData(DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") + "Inside if 574");

            if (!string.IsNullOrEmpty(error.MessageStyle.Message))
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict,
                                              new ErrorResponse
                {
                    Error = error.MessageStyle,
                }));
            }

            var editLines       = _saleManager.CheckEditOptions(sale.Sale_Lines, userCode);
            var enableButton    = _saleManager.EnableCashButton(sale, userCode);
            var userCanWriteOff = _saleManager.EnableWriteOffButton(userCode);
            var saleModel       = SaleMapper.CreateSaleModel(sale, editLines, enableButton, userCanWriteOff);

            _performancelog.Debug($"End,FuelPumpController,AddPrepay,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            WriteUDPData(DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") + "Inside if 584");
            //  s = saleModel;

            return(Request.CreateResponse(HttpStatusCode.OK, saleModel));
        }
        public HttpResponseMessage RefreshPolicies(int tillNumber, int saleNumber)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,PolicyController,RefreshPolicies,{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 policies = _policyManager.RefreshPolicies(userCode);

            if (policies == null)
            {
                return(Request.CreateResponse(
                           HttpStatusCode.Unauthorized,
                           new ErrorResponse
                {
                    Error = new MessageStyle
                    {
                        Message = Resource.Error,
                        MessageType = MessageType.OkOnly
                    }
                }));
            }
            var error = new ErrorMessage();
            var sale  = CacheManager.GetCurrentSaleForTill(tillNumber, saleNumber);

            if (string.IsNullOrEmpty(error.MessageStyle.Message) && sale != null)
            {
                policies.EnableExactChange = _saleManager.EnableCashButton(sale, userCode);
            }
            var allPolicies = (object)policies;

            _performancelog.Debug($"End,PolicyController,RefreshPolicies,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            return(Request.CreateResponse(HttpStatusCode.OK, allPolicies));
        }
        public HttpResponseMessage AddPrepay([FromBody] AddPrepayModel model)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,FuelPumpController,AddPrepay,{string.Empty},{dateStart:hh.mm.ss.ffffff}");

            ErrorMessage error;
            var          accessToken = Request.GetFirstHeaderValueOrDefault <string>("authToken");

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

            var userCode = TokenValidator.GetUserCode(accessToken);

            var sale = _fuelPrepayManager.AddPrepay(model.SaleNumber, model.TillNumber, model.ActivePump, model.Amount, model.FuelGrade, model.IsAmountCash, out error);

            if (!string.IsNullOrEmpty(error.MessageStyle.Message))
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict,
                                              new ErrorResponse
                {
                    Error = error.MessageStyle,
                }));
            }
            if (sale != null)
            {
                var editLines       = _saleManager.CheckEditOptions(sale.Sale_Lines, userCode);
                var enableButton    = _saleManager.EnableCashButton(sale, userCode);
                var userCanWriteOff = _saleManager.EnableWriteOffButton(userCode);
                var saleModel       = SaleMapper.CreateSaleModel(sale, editLines, enableButton, userCanWriteOff);
                _performancelog.Debug($"End,FuelPumpController,AddPrepay,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

                return(Request.CreateResponse(HttpStatusCode.OK, saleModel));
            }


            return(null);
        }
Esempio n. 7
0
        public HttpResponseMessage ChangeUser([FromBody] UserModel user)
        {
            var dateStart = DateTime.Now;

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

            if (user != null)
            {
                ErrorMessage errorMessage;
                string       userName;
                var          result = _loginManager.ChangeUser(userCode, user.UserName,
                                                               user.Password, user.TillNumber, user.ShiftNumber, user.ShiftDate,
                                                               user.PosId, user.UnauthorizedAccess, out errorMessage, out userName);
                if (!string.IsNullOrEmpty(errorMessage.MessageStyle.Message) || !result)
                {
                    var response = new InvalidLoginReponseModel
                    {
                        Error       = errorMessage.MessageStyle,
                        ShutDownPOS = false
                    };
                    return(Request.CreateResponse(HttpStatusCode.Conflict, response));
                }
                var ticks         = DateTime.Now.Ticks;
                var token         = TokenGenerator.GenerateToken(user.UserName, ticks, user.PosId);
                var loginResponse = new LoginResponseModel
                {
                    AuthToken      = token,
                    TrainerCaption = userName
                };
                return(Request.CreateResponse(HttpStatusCode.OK, loginResponse));
            }

            _performancelog.Debug($"End,LoginController,ChangeUser,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            var error = new InvalidLoginReponseModel
            {
                Error = new MessageStyle
                {
                    Message     = Resource.InvalidInformation,
                    MessageType = MessageType.OkOnly
                },
                ShutDownPOS = true
            };

            return(Request.CreateResponse(HttpStatusCode.BadRequest, error));
        }
        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));
        }
Esempio n. 9
0
        public HttpResponseMessage Print(int tillNumber, int shiftNumber, int registerNumber)
        {
            var dateStart = DateTime.Now;

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

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

            var userCode = TokenValidator.GetUserCode(accessToken);

            var report = _dipInputManager.PrintDipReport(tillNumber, shiftNumber, registerNumber, userCode, out error);

            _performancelog.Debug($"End,DipInputController,Save,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            if (!string.IsNullOrEmpty(error.MessageStyle.Message))
            {
                return(Request.CreateResponse(error.StatusCode, new ErrorResponse
                {
                    Error = error.MessageStyle
                }));
            }

            var result = new ReportModel
            {
                ReportName    = report.ReportName,
                ReportContent = report.ReportContent,
                Copies        = report.Copies == 0 ? 1 : report.Copies
            };

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
        /// <summary>
        /// Method to get user code
        /// </summary>
        /// <param name="userCode">Usercode</param>
        /// <param name="httpResponseMessage">HttpResponse</param>
        /// <returns>True or false</returns>
        private bool GetUserCode(out string userCode, out HttpResponseMessage httpResponseMessage)
        {
            userCode            = string.Empty;
            httpResponseMessage = null;
            var accessToken = Request.GetFirstHeaderValueOrDefault <string>("authToken");

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

            userCode = TokenValidator.GetUserCode(accessToken);
            return(false);
        }
        public HttpResponseMessage GetFuelVolume([FromBody] PropaneVolumeModel model)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,FuelPumpController,GetFuelVolume,{string.Empty},{dateStart:hh.mm.ss.ffffff}");

            ErrorMessage error;
            var          accessToken = Request.GetFirstHeaderValueOrDefault <string>("authToken");

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

            var userCode = TokenValidator.GetUserCode(accessToken);

            var sale = _propaneManager.GetVolumeValue(model.GradeId, model.PumpId, model.SaleNumber, model.TillNumber, model.RegisterNumber, model.PropaneValue, out error);

            if (!string.IsNullOrEmpty(error.MessageStyle.Message))
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict,
                                              new ErrorResponse
                {
                    Error = error.MessageStyle,
                }));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, sale));
        }
        public HttpResponseMessage GetTillAuditReport(int tillNumber)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,ReportController,GetTillAuditReport,{string.Empty},{dateStart:hh.mm.ss.ffffff}");

            var till = _tillService.GetTill(tillNumber);

            if (till == null)
            {
                var errorMessage = new ErrorMessage
                {
                    MessageStyle = new MessageStyle
                    {
                        Message = Resource.TillNotExist
                    },
                };
                _performancelog.Debug($"End,ReportController,GetTillAuditReport,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

                return(Request.CreateResponse(HttpStatusCode.NotFound, new ErrorResponse
                {
                    Error = errorMessage.MessageStyle
                }));
            }
            var accessToken = Request.GetFirstHeaderValueOrDefault <string>("authToken");

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

            var userCode = TokenValidator.GetUserCode(accessToken);

            if (!_receiptManager.UserCanAuditTill(userCode))
            {
                var         store          = CacheManager.GetStoreInfo();
                var         offSet         = store?.OffSet ?? 0;
                MessageType temp_VbStyle11 = (int)MessageType.Exclamation + MessageType.OkOnly;
                var         errorMessage   = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 0, 5692, null, temp_VbStyle11)
                };
                _performancelog.Debug($"End,ReportController,GetTillAuditReport,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

                return(Request.CreateResponse(HttpStatusCode.Forbidden, new ErrorResponse
                {
                    Error = errorMessage.MessageStyle
                }));
            }
            var fs = _receiptManager.PrintTillAuditReport(till);

            try
            {
                var content         = Helper.CreateBytes(fs);
                var tillAuditReport = new ReportModel
                {
                    ReportName    = Constants.TillAuditFile,
                    ReportContent = content,
                    Copies        = 1
                };
                _performancelog.Debug($"End,ReportController,GetTillAuditReport,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

                return(Request.CreateResponse(HttpStatusCode.OK, tillAuditReport));
            }
            catch
            {
                _performancelog.Debug($"End,ReportController,GetTillAuditReport,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

                return(Request.CreateResponse(HttpStatusCode.NotFound, new ErrorResponse
                {
                    Error = new MessageStyle {
                        Message = Resource.Error, MessageType = 0
                    }
                }));
            }
        }
        public HttpResponseMessage AddFuelManually([FromBody] ManualFuelModel fuelModel)
        {
            ErrorMessage error;
            var          accessToken = Request.GetFirstHeaderValueOrDefault <string>("authToken");

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

            var userCode = TokenValidator.GetUserCode(accessToken);

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

            var sale = _fuelPumpManager.AddFuelManually(fuelModel.SaleNumber, fuelModel.TillNumber,
                                                        fuelModel.RegisterNumber, userCode, out error, fuelModel.Amount, fuelModel.Grade,
                                                        fuelModel.PumpId, fuelModel.IsCashSelected);

            if (!string.IsNullOrEmpty(error.MessageStyle.Message))
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict,
                                              new ErrorResponse
                {
                    Error = error.MessageStyle,
                }));
            }

            if (sale != null)
            {
                object saleModel;
                var    editLines       = _saleManager.CheckEditOptions(sale.Sale_Lines, userCode);
                var    enableButtons   = _saleManager.EnableCashButton(sale, userCode);
                var    userCanWriteOff = _saleManager.EnableWriteOffButton(userCode);

                if (!string.IsNullOrEmpty(error.MessageStyle.Message))
                {
                    var message = new
                    {
                        error = error.MessageStyle,
                    };
                    var messages = new List <object> {
                        message
                    };

                    saleModel = SaleMapper.CreateSaleModel(sale, editLines, enableButtons, userCanWriteOff, messages);
                }
                else
                {
                    saleModel = SaleMapper.CreateSaleModel(sale, editLines, enableButtons, userCanWriteOff);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, saleModel));
            }

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