Beispiel #1
0
        public HttpResponseMessage SetCustomer(string customerCode, int tillNumber, int saleNumber, byte registerNumber)
        {
            var dateStart = DateTime.Now;

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

            ErrorMessage        error;
            string              userCode;
            HttpResponseMessage httpResponseMessage;

            if (GetUserCode(out userCode, out httpResponseMessage))
            {
                return(httpResponseMessage);
            }
            var sale = _saleManager.SetCustomer(customerCode, saleNumber, tillNumber, userCode, registerNumber,
                                                string.Empty, out error);

            if (!string.IsNullOrEmpty(error.MessageStyle.Message) && sale == null)
            {
                return(Request.CreateResponse(error.StatusCode,
                                              new ErrorResponse
                {
                    Error = error.MessageStyle,
                }));
            }
            else if (!string.IsNullOrEmpty(error.MessageStyle.Message) && 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);
                if (saleModel.SaleLineErrors == null)
                {
                    saleModel.SaleLineErrors = new List <object>();
                    saleModel.SaleLineErrors.Add(new ErrorResponse
                    {
                        Error = error.MessageStyle,
                    });
                }
                else
                {
                    saleModel.SaleLineErrors.Add(new ErrorResponse
                    {
                        Error = error.MessageStyle,
                    });
                }
                _performancelog.Debug($"End,SaleController,SetCustomer,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

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

            if (error.MessageStyle != null && string.IsNullOrEmpty(error.MessageStyle.Message))
            {
                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,SaleController,SetCustomer,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

                return(Request.CreateResponse(HttpStatusCode.OK, saleModel));
            }
            return(null);
        }
Beispiel #2
0
        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));
        }