public HttpResponseMessage ReturnSaleItems([FromBody] ReturnSaleModel model) { var dateStart = DateTime.Now; _performancelog.Debug($"Start,ReturnSaleController,returnItems,{string.Empty},{dateStart:hh.mm.ss.ffffff}"); ErrorMessage message; List <ErrorMessage> saleLineMessages; string userCode; HttpResponseMessage httpResponseMessage; if (GetUserCode(out userCode, out httpResponseMessage)) { return(httpResponseMessage); } var user = CacheManager.GetUser(userCode) ?? _loginManager.GetUser(userCode); if (model.SaleLines == null || model.SaleLines.Length <= 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse { Error = new MessageStyle { Message = Resource.LineRequired, MessageType = MessageType.OkOnly } })); } var sale = _returnSaleManager.ReturnSaleItems(user, model.SaleTillNumber, model.TillNumber, model.SaleNumber, model.SaleLines, model.IsCorrection, model.ReasonType, model.ReasonCode, out message, out saleLineMessages); if (!string.IsNullOrEmpty(message.MessageStyle.Message)) { _performancelog.Debug($"End,ReturnSaleController,returnItems,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse { Error = message.MessageStyle })); } var editLines = _saleManager.CheckEditOptions(sale.Sale_Lines, userCode); var messages = new List <object>(); if (saleLineMessages.Count > 0) { messages.AddRange(saleLineMessages.Select(saleLineMessage => new { error = saleLineMessage.MessageStyle, })); } var enableButtons = _saleManager.EnableCashButton(sale, userCode); var userCanWriteOff = _saleManager.EnableWriteOffButton(userCode); var saleModel = messages.Count > 0 ? SaleMapper.CreateSaleModel(sale, editLines, enableButtons, userCanWriteOff, messages) : SaleMapper.CreateSaleModel(sale, editLines, enableButtons, userCanWriteOff); _performancelog.Debug($"End,ReturnSaleController,returnItems,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse(HttpStatusCode.OK, saleModel)); }
public HttpResponseMessage ReturnSale([FromBody] ReturnSaleModel model) { var dateStart = DateTime.Now; ErrorMessage message; List <ErrorMessage> saleLineMessages; _performancelog.Debug($"Start,ReturnSaleController,return,{string.Empty},{dateStart:hh.mm.ss.ffffff}"); string userCode; HttpResponseMessage httpResponseMessage; if (GetUserCode(out userCode, out httpResponseMessage)) { return(httpResponseMessage); } var user = CacheManager.GetUser(userCode) ?? _loginManager.GetUser(userCode); Report fs; string fileName; var sale = _returnSaleManager.ReturnSale(user, model.SaleNumber, model.TillNumber, model.SaleTillNumber, model.IsCorrection, model.ReasonType, model.ReasonCode, out message, out saleLineMessages, out fs, out fileName); if (!string.IsNullOrEmpty(message.MessageStyle.Message)) { _performancelog.Debug( $"End,ReturnSaleController,return,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse { Error = message.MessageStyle })); } var editLines = _saleManager.CheckEditOptions(sale.Sale_Lines, userCode); var messages = new List <object>(); if (saleLineMessages.Count > 0) { messages.AddRange(saleLineMessages.Select(saleLineMessage => new { error = saleLineMessage.MessageStyle, })); } var enableButtons = _saleManager.EnableCashButton(sale, userCode); var userCanWriteOff = _saleManager.EnableWriteOffButton(userCode); var saleModel = messages.Count > 0 ? SaleMapper.CreateSaleModel(sale, editLines, enableButtons, userCanWriteOff, messages) : SaleMapper.CreateSaleModel(sale, editLines, enableButtons, userCanWriteOff); var returnSale = new ReturnSaleResponseModel { Sale = saleModel }; if (fs != null) { returnSale.Receipt = new ReportModel { ReportContent = fs.ReportName, ReportName = fs.ReportContent, Copies = 1 }; } _performancelog.Debug($"End,ReturnSaleController,return,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse(HttpStatusCode.OK, returnSale)); }