public HttpResponseMessage GetSale(int saleNumber, int tillNumber) { var dateStart = DateTime.Now; _performancelog.Debug($"Start,ReturnSaleController,GetSale,{string.Empty},{dateStart:hh.mm.ss.ffffff}"); string userCode; HttpResponseMessage httpResponseMessage; if (GetUserCode(out userCode, out httpResponseMessage)) { return(httpResponseMessage); } ErrorMessage message; var sale = _returnSaleManager.GetSale(saleNumber, tillNumber, out message); if (!string.IsNullOrEmpty(message.MessageStyle.Message)) { _performancelog.Debug($"End,ReturnSaleController,GetSale,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse(HttpStatusCode.NotFound, new ErrorResponse { Error = message.MessageStyle })); } var editLines = _saleManager.CheckEditOptions(sale.Sale_Lines, userCode); var enableButtons = _saleManager.EnableCashButton(sale, userCode); var userCanWriteOff = _saleManager.EnableWriteOffButton(userCode); var saleModel = SaleMapper.CreateSaleModel(sale, editLines, enableButtons, userCanWriteOff); _performancelog.Debug($"End,ReturnSaleController,GetSale,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse(HttpStatusCode.OK, saleModel)); }
public HttpResponseMessage InitializeSale(int tillNumber, int registerNumber) { var dateStart = DateTime.Now; _performancelog.Debug($"Start,SaleController,InitializeSale,{string.Empty},{dateStart:hh.mm.ss.ffffff}"); ErrorMessage message; string userCode; HttpResponseMessage httpResponseMessage; if (GetUserCode(out userCode, out httpResponseMessage)) { return(httpResponseMessage); } var sale = _saleManager.InitializeSale(tillNumber, registerNumber, userCode, out message); if (message?.MessageStyle?.Message != null) { return(Request.CreateResponse(HttpStatusCode.Conflict, message)); } 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,SaleController,InitializeSale,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse(HttpStatusCode.OK, saleModel)); } return(null); }
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 AdjustGivexCard([FromBody] AdjustGivexModel givexModel) { var dateStart = DateTime.Now; _performancelog.Debug($"Start,GivexController,AdjustGivexCard,{string.Empty},{dateStart:hh.mm.ss.ffffff}"); ErrorMessage errorMessage; HttpResponseMessage responseMessage; var cardNumber = givexModel.GivexCardNumber; if (!ValidateGivexCard(ref cardNumber, out responseMessage)) { return(responseMessage); } givexModel.GivexCardNumber = cardNumber; if (!ValidateStockCode(givexModel.StockCode, out responseMessage)) { return(responseMessage); } string userCode; HttpResponseMessage httpResponseMessage; if (GetUserCode(out userCode, out httpResponseMessage)) { return(httpResponseMessage); } if (Conversion.Val(givexModel.Amount) <= 0) { const MessageType messageType = (int)MessageType.OkOnly + MessageType.Critical; var offSet = _policyManager.LoadStoreInfo().OffSet; return(Request.CreateResponse(HttpStatusCode.NotAcceptable, new ErrorResponse { Error = _resourceManager.CreateMessage(offSet, 32, 94, null, messageType), })); } Report giveReceipt; var sale = _givexManager.AdjustGivexCard(givexModel.GivexCardNumber, givexModel.Amount, userCode, givexModel.TillNumber, givexModel.SaleNumber, givexModel.StockCode, out giveReceipt, out errorMessage); if (!string.IsNullOrEmpty(errorMessage.MessageStyle.Message)) { return(Request.CreateResponse(errorMessage.StatusCode, new ErrorResponse { Error = errorMessage.MessageStyle })); } var editLines = _saleManager.CheckEditOptions(sale.Sale_Lines, userCode); var enableButtons = _saleManager.EnableCashButton(sale, userCode); var userCanWriteOff = _saleManager.EnableWriteOffButton(userCode); var saleModel = SaleMapper.CreateSaleModel(sale, editLines, enableButtons, userCanWriteOff); var response = new GivexResponseModel { Sale = saleModel, Receipt = giveReceipt }; _performancelog.Debug($"End,GivexController,AdjustGivexCard,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse(HttpStatusCode.OK, response)); }
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 } })); }
public HttpResponseMessage GetCustomerByCard([FromBody] SearchBycardModel model) { var dateStart = DateTime.Now; _performancelog.Debug($"Start,CustomerController,GetCustomerByCard,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}"); MessageStyle message; if (string.IsNullOrEmpty(model.CardNumber)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse { Error = new MessageStyle { Message = Resource.CardRequired, MessageType = MessageType.OkOnly } })); } var customer = _customerManager.SearchCustomerCard(model.CardNumber, model.IsLoyaltycard, out message); if (!string.IsNullOrEmpty(message.Message)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse { Error = new MessageStyle { Message = message.Message, MessageType = MessageType.OkOnly } })); } if (customer == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse { Error = new MessageStyle { Message = Resource.CustomerNotExists, MessageType = MessageType.OkOnly } })); } string userCode; ErrorMessage error = new ErrorMessage(); HttpResponseMessage httpResponseMessage; if (GetUserCode(out userCode, out httpResponseMessage)) { return(httpResponseMessage); } var sale = _saleManager.SetCustomer(customer.Code, model.SaleNumber, model.TillNumber, userCode, 0, model.CardNumber, out error); if (!string.IsNullOrEmpty(error.MessageStyle.Message)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse { Error = error.MessageStyle })); } if (sale != null) { var editLines = _saleManager.CheckEditOptions(sale.Sale_Lines, userCode); var enableButtons = _saleManager.EnableCashButton(sale, userCode); var userCanWriteOff = _saleManager.EnableWriteOffButton(userCode); var saleModel = SaleMapper.CreateSaleModel(sale, editLines, enableButtons, userCanWriteOff); } var customerModel = GetLoyaltyCustomerResponseModel(customer); _performancelog.Debug($"End,CustomerController,GetCustomerByCard,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse(HttpStatusCode.OK, customerModel)); }