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);
        }