当前位置: 首页>>代码示例>>C#>>正文


C# DataClassesDataContext.XEROPurchases方法代码示例

本文整理汇总了C#中DataClassesDataContext.XEROPurchases方法的典型用法代码示例。如果您正苦于以下问题:C# DataClassesDataContext.XEROPurchases方法的具体用法?C# DataClassesDataContext.XEROPurchases怎么用?C# DataClassesDataContext.XEROPurchases使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataClassesDataContext的用法示例。


在下文中一共展示了DataClassesDataContext.XEROPurchases方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PostPurchasesToXero

        public HttpResponseMessage PostPurchasesToXero(SearchFilter searchFilter)
        {
            using (DataClassesDataContext context = new DataClassesDataContext())
            {
                try
                {
                    var purchases = context.XEROPurchases(searchFilter.StartDate, searchFilter.EndDate);
                    foreach (var purchase in purchases)
                    {
                        PurchaseToInvoiceViewModelConverter purchaseConverter = new PurchaseToInvoiceViewModelConverter();
                        try
                        {
                            InvoiceViewModel invoiceViewModel = purchaseConverter.Convert(purchase);
                            purchasesToPostList.Add(invoiceViewModel);
                        }
                        catch (InvoiceValidationException e)
                        {
                            ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                            return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, e.Message);
                        }
                        catch (SupplierDoesNotExistException e)
                        {
                            ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                            return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, e.Message);
                        }
                    }
                }
                catch (System.Data.SqlClient.SqlException)
                {
                    ModelStateDictionary dictionary = errorStringConvertor.Convert("To many Purchases in daterange");
                    return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
                }
            }
            try
            {
                xeroLogic.ExportInvoices(purchasesToPostList);
            }
            catch (XeroApiLimitException e)
            {
                ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                return this.Request.CreateErrorResponse(HttpStatusCode.BadGateway, dictionary);
            }
            catch (XeroException e)
            {
                ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
            }
            catch (XeroApiValidationException e)
            {
                ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
            }
            catch (Exception)
            {
                ModelStateDictionary dictionary = errorStringConvertor.Convert("Something went wrong. Please check the data and try again.");
                return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, dictionary);
            }

            return this.Request.CreateResponse(HttpStatusCode.OK);
        }
开发者ID:markplaatsman,项目名称:XeroIntegration,代码行数:60,代码来源:ExportPurchaseToXeroWebApiController.cs

示例2: GetPurchases

        public HttpResponseMessage GetPurchases(SearchFilter searchFilter)
        {
            List<PurchaseViewModel> resultList = new List<PurchaseViewModel>();
            using (DataClassesDataContext context = new DataClassesDataContext())
            {
                try
                {
                    var purchases = context.XEROPurchases(searchFilter.StartDate, searchFilter.EndDate);

                    foreach (var purchase in purchases)
                    {
                        PurchaseViewModel purchaseViewModel = new PurchaseViewModel()
                        {
                            InvoiceNumber = purchase.InvoiceNumber,
                            EmailAddress = purchase.EmailAddress,
                            Address1 = purchase.POAddressLine1,
                            Address2 = purchase.POAddressLine2,
                            Address3 = purchase.POAddressLine3,
                            Address4 = purchase.POAddressLine4,
                            City = purchase.POCity,
                            Region = purchase.PORegion,
                            Country = purchase.POCountry,
                            PostalCode = purchase.POPostalCode,
                            InvoiceDate = purchase.InvoiceDate.GetValueOrDefault().ToString("dd-MM-yy"),
                            DueDate = purchase.DueDate.GetValueOrDefault().ToString("dd-MM-yy"),
                            InventoryItemCode = purchase.InventoryItemCode.ToString(),
                            Description = purchase.Description,
                            Quantity = purchase.Quantity.ToString(),
                            UnitAmount = purchase.UnitAmount.ToString(),
                            AccountCode = purchase.AccountCode.ToString(),
                            TaxType = purchase.TaxType,
                            TrackingName = purchase.TrackingName1,
                            TrackingOption = purchase.TrackingOption1,
                            Currency = purchase.Currency,

                        };

                        try
                        {
                            purchaseViewModel.ContactName = getSupplierName(purchase.ContactName);
                        }
                        catch(PurchaseValidationException e)
                        {
                            ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                            return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
                        }
                        catch (SupplierDoesNotExistException e )
                        {
                            ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                            return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
                        }

                        resultList.Add(purchaseViewModel);
                    }
                }
                catch (System.Data.SqlClient.SqlException)
                {
                    ModelStateDictionary dictionary = errorStringConvertor.Convert("To many invoices in daterange");
                    return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
                }

                return this.Request.CreateResponse(HttpStatusCode.OK, resultList);
            }
        }
开发者ID:markplaatsman,项目名称:XeroIntegration,代码行数:64,代码来源:PurchasesWebApiController.cs


注:本文中的DataClassesDataContext.XEROPurchases方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。