Exemple #1
0
        public HttpResponseMessage AddSaleLineItem([FromBody] AddSaleLineModel saleLineModel)
        {
            var dateStart = DateTime.Now;

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

            ErrorMessage        error;
            string              userCode;
            HttpResponseMessage httpResponseMessage;

            if (GetUserCode(out userCode, out httpResponseMessage))
            {
                return(httpResponseMessage);
            }
            if (saleLineModel == null)
            {
                return(Request.CreateResponse(
                           HttpStatusCode.BadRequest,
                           new ErrorResponse
                {
                    Error = new MessageStyle {
                        Message = Constants.InvalidRequest
                    }
                }));
            }

            var sale = _saleManager.AddSaleLineItem(userCode, saleLineModel.TillNumber,
                                                    saleLineModel.SaleNumber, saleLineModel.RegisterNumber, saleLineModel.StockCode,
                                                    saleLineModel.Quantity, saleLineModel.IsReturnMode, saleLineModel.GiftCard, out error);

            if (!string.IsNullOrEmpty(error.MessageStyle.Message) && error.StatusCode != HttpStatusCode.OK)
            {
                return(Request.CreateResponse(error.StatusCode,
                                              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);
                }
                _performancelog.Debug($"End,SaleController,AddSaleLineItem,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

                return(Request.CreateResponse(HttpStatusCode.OK, saleModel));
            }
            return(null);
        }
Exemple #2
0
        public HttpResponseMessage VerifyAndAddSaleLineItem([FromBody] AddSaleLineModel model)
        {
            var dateStart = DateTime.Now;

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

            ErrorMessage        error;
            string              userCode;
            HttpResponseMessage httpResponseMessage;

            if (GetUserCode(out userCode, out httpResponseMessage))
            {
                return(httpResponseMessage);
            }
            if (model == null)
            {
                return(Request.CreateResponse(
                           HttpStatusCode.BadRequest,
                           new ErrorResponse
                {
                    Error = new MessageStyle {
                        Message = Constants.InvalidRequest
                    }
                }));
            }

            var stockMessage = _saleLineManager.CheckStockConditions(model.SaleNumber, model.TillNumber, model.StockCode, userCode,
                                                                     model.IsReturnMode, (float)model.Quantity, out error);

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

            //if (stockMessage.AddStockPage.OpenAddStockPage || stockMessage.GiftCertPage.OpenGiftCertPage || stockMessage.GivexPage.OpenGivexPage || stockMessage.RestrictionPage.OpenRestrictionPage || !string.IsNullOrEmpty(stockMessage.QuantityMessage.Message) || !string.IsNullOrEmpty(stockMessage.RegularPriceMessage.Message))
            if (stockMessage.AddStockPage.OpenAddStockPage ||
                stockMessage.GiftCertPage.OpenGiftCertPage ||
                stockMessage.GivexPage.OpenGivexPage ||
                stockMessage.RestrictionPage.OpenRestrictionPage ||
                stockMessage.PSInetPage.OpenPSInetPage ||
                !string.IsNullOrEmpty(stockMessage.QuantityMessage.Message) ||
                !string.IsNullOrEmpty(stockMessage.RegularPriceMessage.Message))
            {
                return(Request.CreateResponse(HttpStatusCode.PartialContent, stockMessage));
            }

            if (!stockMessage.CanManuallyEnterProduct && model.IsManuallyAdded)
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict,
                                              new ErrorResponse
                {
                    Error = new MessageStyle
                    {
                        Message = stockMessage.ManuallyEnterMessage,
                        MessageType = 0
                    }
                }));
            }

            var sale = _saleManager.VerifyAddSaleLineItem(userCode, model.TillNumber,
                                                          model.SaleNumber, model.RegisterNumber, model.StockCode,
                                                          model.Quantity, model.IsReturnMode, model.GiftCard, out error);

            if (!string.IsNullOrEmpty(error.MessageStyle.Message) && error.StatusCode != HttpStatusCode.OK)
            {
                return(Request.CreateResponse(error.StatusCode,
                                              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);
                }
                _performancelog.Debug($"End,SaleController,VerifyAndAddSaleLineItem,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

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