예제 #1
0
        public PositioveResponseCaseModel positiveResponse(List <PositiveResponseModel> PositiveResponseL, string connectionString, string sessionTicket, out TransactionalInformation transaction)
        {
            var method             = MethodInfo.GetCurrentMethod();
            var ipInfo             = Util.GetIPInfo(HttpContext.Current.Request);
            var userSecurityTicket = VerifySessionToken(sessionTicket);

            transaction = new TransactionalInformation();

            PositioveResponseCaseModel positiveModel = new PositioveResponseCaseModel();

            try
            {
                var billPositionsAwaitingResponseCount = cls_Get_BillPositionNumbers_waiting_Hip_Response.Invoke(connectionString, new P_CAS_GBPNwHipR_1853()
                {
                    // this is done to remove leading zeros
                    BillNumbers = PositiveResponseL.Select(t => Double.Parse(t.InvoiceNumberHIP).ToString()).ToArray()
                }, userSecurityTicket).Result.position_count;

                positiveModel.CasesImported    = PositiveResponseL.Count;
                positiveModel.CasesImportedXLs = PositiveResponseL.Count - billPositionsAwaitingResponseCount;
                positiveModel.positiveModelL   = PositiveResponseL;
            }
            catch (Exception ex)
            {
                Logger.LogInfo(new LogEntry(ipInfo.address, ipInfo.agent, connectionString, method, userSecurityTicket, ex));

                transaction.ReturnMessage = new List <string>();
                string errorMessage = ex.Message;
                transaction.ReturnStatus = false;
                transaction.ReturnMessage.Add(errorMessage);
                transaction.IsAuthenicated = true;
                transaction.IsException    = true;
            }

            return(positiveModel);
        }
예제 #2
0
        public async Task <HttpResponseMessage> PositiveResponse()
        {
            var method = MethodInfo.GetCurrentMethod();
            var ipInfo = Util.GetIPInfo(HttpContext.Current.Request);

            try
            {
                TransactionalInformation transaction = new TransactionalInformation();
                ResponseCasesApiModel    apiModel    = new ResponseCasesApiModel();
                if (!Request.Content.IsMimeMultipartContent())
                {
                    return(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType));
                }
                List <PositiveResponseModel> PositiveResponseL = new List <PositiveResponseModel>();
                var provider = new MultipartMemoryStreamProvider();
                await Request.Content.ReadAsMultipartAsync(provider);

                foreach (var file in provider.Contents)
                {
                    var    filename      = file.Headers.ContentDisposition.FileName.Trim('\"');
                    int    i             = filename.LastIndexOf('.');
                    string fileExtension = filename.Substring(filename.Length - 4);

                    if (fileExtension == "xlsx".ToLower() || fileExtension == ".xls".ToLower())
                    {
                        apiModel.isPositiveResponce = true;
                        var buffer = await file.ReadAsByteArrayAsync();

                        MemoryStream ms        = new MemoryStream(buffer);
                        bool         hasHeader = true;


                        System.Data.DataTable excelData = ExcelUtils.getDataFromExcelFileNoPath(ms, hasHeader);
                        try
                        {
                            foreach (System.Data.DataRow item in excelData.Rows)
                            {
                                if (item.ItemArray.Any() && item.ItemArray[0].ToString() != "")
                                {
                                    PositiveResponseModel positiveModel = new PositiveResponseModel();
                                    try
                                    {
                                        string invoiceNo = item.ItemArray[2].ToString();
                                        if (invoiceNo != "")
                                        {
                                            var bill_position_number = "000000000000";
                                            bill_position_number          += (double.Parse(item.ItemArray[2].ToString())).ToString();
                                            bill_position_number           = bill_position_number.Substring(bill_position_number.Length - 12, 12);
                                            positiveModel.InvoiceNumberHIP = bill_position_number;
                                            PositiveResponseL.Add(positiveModel);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                    };
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            var userSecurityTicket = new BaseVerification().VerifySessionToken(SessionToken);
                            Logger.LogInfo(new LogEntry(ipInfo.address, ipInfo.agent, connectionString, method, userSecurityTicket, ex));

                            transaction.ReturnMessage = new List <string>();
                            transaction.IsException   = true;
                            transaction.ReturnMessage.Add(ex.StackTrace);
                            transaction.ReturnMessage.Add(ex.Message);
                            return(Request.CreateResponse <TransactionalInformation>(HttpStatusCode.BadRequest, transaction));
                        }
                    }
                    else if (fileExtension.ToLower() == ".edi" || fileExtension.ToLower() == ".txt")
                    {
                        try
                        {
                            var buffer = await file.ReadAsByteArrayAsync();

                            MemoryStream ms     = new MemoryStream(buffer);
                            EDIMessage   ediMsg = new EDIMessage(ms);
                            var          result = ediMsg.GetParsedEdifactFile();
                            List <NegativeResponseModel> negativeResponseList = new List <NegativeResponseModel>();

                            foreach (var item in result.transmitionMessages)
                            {
                                NegativeResponseModel response = new NegativeResponseModel();
                                response.billPositionNumber = item.Rgi.Segment5.Value.Split('K').Last();
                                PositiveResponseL.Add(new Models.PositiveResponseModel()
                                {
                                    InvoiceNumberHIP = item.Rgi.Segment5.Value.Split('K').Last()
                                });
                                response.message = String.Join("; ", item.Fhl.Select(t => t.Segment4.Value).ToArray());
                                response.hipId   = item.Ivk.Segment4.Value;

                                negativeResponseList.Add(response);
                            }

                            var billNumberIDsList   = negativeResponseList.Select(j => j.billPositionNumber).ToList();
                            var nonEligibleStatuses = dashboardDataService.CasesWithNonEligibleStatuses(billNumberIDsList, connectionString, SessionToken, out transaction);

                            apiModel.NonEligibleStatuses     += nonEligibleStatuses.Count;
                            apiModel.TotalCases              += negativeResponseList.Count;
                            apiModel.isPositiveResponce       = false;
                            apiModel.NegativeModel.ediMessage = ediMsg.RawMessage;
                            apiModel.NegativeModel.ediName    = filename;
                            var dateToHip_string = result.Unb.Segment5.Value;
                            try
                            {
                                apiModel.NegativeModel.dateOfTransmitionToHIP = DateTime.ParseExact(dateToHip_string, "yyyyMMdd", new CultureInfo("de", true));
                            }
                            catch
                            {
                            }

                            if (nonEligibleStatuses.Count > 0)
                            {
                                foreach (var billNumber in nonEligibleStatuses)
                                {
                                    var itemToRemove = negativeResponseList.Where(h => double.Parse(h.billPositionNumber) == double.Parse(billNumber)).SingleOrDefault();
                                    if (itemToRemove != null)
                                    {
                                        negativeResponseList.Remove(itemToRemove);
                                    }
                                }
                                apiModel.NegativeModel.NegativeResponseList.AddRange(negativeResponseList);
                            }
                            else
                            {
                                apiModel.NegativeModel.NegativeResponseList.AddRange(negativeResponseList);
                            }
                        }
                        catch (Exception ex)
                        {
                            var userSecurityTicket = new BaseVerification().VerifySessionToken(SessionToken);
                            Logger.LogInfo(new LogEntry(ipInfo.address, ipInfo.agent, connectionString, method, userSecurityTicket, ex));

                            transaction.ReturnMessage = new List <string>();
                            transaction.IsException   = true;
                            transaction.ReturnMessage.Add(ex.StackTrace);
                            transaction.ReturnMessage.Add(ex.Message);
                            return(Request.CreateResponse <TransactionalInformation>(HttpStatusCode.BadRequest, transaction));
                        }
                    }
                }
                PositioveResponseCaseModel model = dashboardDataService.positiveResponse(PositiveResponseL, connectionString, SessionToken, out transaction);
                apiModel.PositiveModel       = model;
                apiModel.TotalCases          = model.CasesImported;
                apiModel.NonEligibleStatuses = model.CasesImportedXLs;

                if (transaction.ReturnStatus)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, apiModel));
                }

                return(Request.CreateResponse <TransactionalInformation>(HttpStatusCode.BadRequest, transaction));
            }
            catch (Exception ex)
            {
                var userSecurityTicket = new BaseVerification().VerifySessionToken(SessionToken);
                Logger.LogInfo(new LogEntry(ipInfo.address, ipInfo.agent, connectionString, method, userSecurityTicket, ex));

                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }