public Offer ApiToDomain(Api.Offer value) { if (value == null) { return(null); } IReduction reduction = null; if (!string.IsNullOrEmpty(value.Reduction)) { if (value.Reduction.EndsWith("%")) { reduction = new PercentReduction { Value = float.Parse(value.Reduction.Replace("%", ""), CultureInfo.InvariantCulture) }; } else { reduction = new AbsoluteReduction { Value = float.Parse(value.Reduction, CultureInfo.InvariantCulture) }; } } return(new Offer { Id = int.Parse(value.Id, CultureInfo.InvariantCulture), TemplateId = value.TemplateId.ToOptionalInt(), CustomerPortalUrl = value.CustomerPortalUrl, ClientId = int.Parse(value.ClientId, CultureInfo.InvariantCulture), ContactId = value.ContactId.ToOptionalInt(), OfferNumber = value.OfferNumber, Number = value.Number.ToOptionalInt(), NumberPre = value.NumberPre, NumberLength = int.Parse(value.NumberLength, CultureInfo.InvariantCulture), Title = value.Title, Date = DateTime.Parse(value.Date, CultureInfo.InvariantCulture), Address = value.Address, Label = value.Label, Intro = value.Intro, Note = value.Note, TotalGross = float.Parse(value.TotalGross, CultureInfo.InvariantCulture), TotalNet = float.Parse(value.TotalNet, CultureInfo.InvariantCulture), CurrencyCode = value.CurrencyCode, TotalGrossUnreduced = float.Parse(value.TotalGrossUnreduced, CultureInfo.InvariantCulture), TotalNetUnreduced = float.Parse(value.TotalNetUnreduced, CultureInfo.InvariantCulture), Created = DateTime.Parse(value.Created, CultureInfo.InvariantCulture), Updated = DateTime.Parse(value.Updated, CultureInfo.InvariantCulture), NetGross = value.NetGross.ToNetGrossType(), Status = value.Status.ToOfferStatus(), //Taxes = _taxMapper.ApiToDomain(value.Taxes), Quote = float.Parse(value.Quote, CultureInfo.InvariantCulture), Reduction = reduction, }); }
public OfferItem ApiToDomain(Api.OfferItem value) { if (value == null) { return(null); } IReduction reduction = null; if (!string.IsNullOrEmpty(value.Reduction) && value.Reduction != "null") { if (value.Reduction.EndsWith("%")) { reduction = new PercentReduction { Value = float.Parse(value.Reduction.Replace("%", ""), CultureInfo.InvariantCulture) }; } else { reduction = new AbsoluteReduction { Value = float.Parse(value.Reduction, CultureInfo.InvariantCulture) }; } } return(new OfferItem { Id = int.Parse(value.Id, CultureInfo.InvariantCulture), Reduction = reduction, OfferId = int.Parse(value.OfferId, CultureInfo.InvariantCulture), ArticleId = value.ArticleId.ToOptionalInt(), Description = value.Description, Position = int.Parse(value.Position, CultureInfo.InvariantCulture), Title = value.Title, Unit = value.Unit, TaxName = value.TaxName, TotalNet = float.Parse(value.TotalNet, CultureInfo.InvariantCulture), Quantity = float.Parse(value.Quantity, CultureInfo.InvariantCulture), TotalNetUnreduced = float.Parse(value.TotalNetUnreduced, CultureInfo.InvariantCulture), TotalGross = float.Parse(value.TotalGross, CultureInfo.InvariantCulture), TotalGrossUnreduced = float.Parse(value.TotalGrossUnreduced, CultureInfo.InvariantCulture), UnitPrice = float.Parse(value.UnitPrice, CultureInfo.InvariantCulture), TaxRate = value.TaxRate.ToOptionalFloat() }); }
public Invoice ApiToDomain(Api.Invoice value) { if (value == null) { return(null); } SupplyDateType?supplyDateType; ISupplyDate supplyDate; switch (value.SupplyDateType.ToLowerInvariant()) { case "supply_date": supplyDateType = SupplyDateType.SupplyDate; supplyDate = new DateSupplyDate { Date = value.SupplyDate.ToOptionalDateTime() }; break; case "delivery_date": supplyDateType = SupplyDateType.DeliveryDate; supplyDate = new DateSupplyDate { Date = value.SupplyDate.ToOptionalDateTime() }; break; case "supply_text": supplyDateType = SupplyDateType.SupplyDate; supplyDate = new FreeTextSupplyDate { Text = value.SupplyDate }; break; case "delivery_text": supplyDateType = SupplyDateType.DeliveryDate; supplyDate = new FreeTextSupplyDate { Text = value.SupplyDate }; break; case "": supplyDateType = null; supplyDate = null; break; default: throw new ArgumentOutOfRangeException(); } IReduction reduction = null; if (!string.IsNullOrEmpty(value.Reduction)) { if (value.Reduction.EndsWith("%")) { reduction = new PercentReduction { Value = float.Parse(value.Reduction.Replace("%", ""), CultureInfo.InvariantCulture) }; } else { reduction = new AbsoluteReduction { Value = float.Parse(value.Reduction, CultureInfo.InvariantCulture) }; } } return(new Invoice { Id = value.Id.ToInt(), InvoiceId = value.InvoiceId.ToOptionalInt(), ConfirmationId = value.ConfirmationId.ToOptionalInt(), OfferId = value.OfferId.ToOptionalInt(), RecurringId = value.RecurringId.ToOptionalInt(), TemplateId = value.TemplateId.ToOptionalInt(), CustomerPortalUrl = value.CustomerPortalUrl.Sanitize(), ClientId = value.ClientId.ToInt(), ContactId = value.ContactId.ToOptionalInt(), InvoiceNumber = value.InvoiceNumber, Number = value.Number.ToOptionalInt(), NumberPre = value.NumberPre.Sanitize(), NumberLength = value.NumberLength.ToInt(), Title = value.Title.Sanitize(), Date = value.Date.ToOptionalDateTime(), Address = value.Address.Sanitize(), Label = value.Label.Sanitize(), Intro = value.Intro.Sanitize(), Note = value.Note.Sanitize(), TotalGross = value.TotalGross.ToFloat(), TotalNet = value.TotalNet.ToFloat(), CurrencyCode = value.CurrencyCode, TotalGrossUnreduced = value.TotalGrossUnreduced.ToFloat(), TotalNetUnreduced = value.TotalNetUnreduced.ToFloat(), Created = value.Created.ToDateTime(), DueDate = value.DueDate.ToOptionalDateTime(), DueDays = value.DueDays.ToOptionalInt(), NetGross = value.NetGross.ToNetGrossType(), SupplyDate = supplyDate, SupplyDateType = supplyDateType, Status = value.Status.ToInvoiceStatus(), PaymentTypes = value.PaymentTypes.ToStringList(), Taxes = _taxMapper.ApiToDomain(value.Taxes), Quote = value.Quote.ToFloat(), Reduction = reduction, DiscountRate = value.DiscountRate.ToOptionalFloat(), DiscountDate = value.DiscountDate.ToOptionalDateTime(), DiscountDays = value.DiscountDays.ToOptionalInt(), DiscountAmount = value.DiscountAmount.ToOptionalFloat(), PaidAmount = value.PaidAmount.ToFloat(), OpenAmount = value.OpenAmount.ToFloat() }); }
private static Invoice ToDomain(this Api.Invoice value) { if (value == null) { return(null); } NetGrossType netGrossType; switch (value.NetGross.ToLowerInvariant()) { case "net": netGrossType = NetGrossType.Net; break; case "gross": netGrossType = NetGrossType.Gross; break; default: throw new ArgumentOutOfRangeException(); } SupplyDateType?supplyDateType; ISupplyDate supplyDate; switch (value.SupplyDateType.ToLowerInvariant()) { case "supply_date": supplyDateType = SupplyDateType.SupplyDate; supplyDate = new DateSupplyDate { Date = value.SupplyDate.ToOptionalDateTime() }; break; case "delivery_date": supplyDateType = SupplyDateType.DeliveryDate; supplyDate = new DateSupplyDate { Date = value.SupplyDate.ToOptionalDateTime() }; break; case "supply_text": supplyDateType = SupplyDateType.SupplyDate; supplyDate = new FreeTextSupplyDate { Text = value.SupplyDate }; break; case "delivery_text": supplyDateType = SupplyDateType.DeliveryDate; supplyDate = new FreeTextSupplyDate { Text = value.SupplyDate }; break; case "": supplyDateType = null; supplyDate = null; break; default: throw new ArgumentOutOfRangeException(); } InvoiceStatus status; switch (value.Status.ToLowerInvariant()) { case "draft": status = InvoiceStatus.Draft; break; case "open": status = InvoiceStatus.Open; break; case "overdue": status = InvoiceStatus.Overdue; break; case "paid": status = InvoiceStatus.Paid; break; case "canceled": status = InvoiceStatus.Canceled; break; default: throw new ArgumentOutOfRangeException(); } IReduction reduction = null; if (!string.IsNullOrEmpty(value.Reduction)) { if (value.Reduction.EndsWith("%")) { reduction = new PercentReduction { Value = float.Parse(value.Reduction.Replace("%", ""), CultureInfo.InvariantCulture) }; } else { reduction = new AbsoluteReduction { Value = float.Parse(value.Reduction, CultureInfo.InvariantCulture) }; } } return(new Invoice { Id = int.Parse(value.Id, CultureInfo.InvariantCulture), InvoiceId = value.InvoiceId.ToOptionalInt(), ConfirmationId = value.ConfirmationId.ToOptionalInt(), OfferId = value.OfferId.ToOptionalInt(), RecurringId = value.RecurringId.ToOptionalInt(), TemplateId = value.TemplateId.ToOptionalInt(), CustomerPortalUrl = value.CustomerPortalUrl, ClientId = int.Parse(value.ClientId, CultureInfo.InvariantCulture), ContactId = value.ContactId.ToOptionalInt(), InvoiceNumber = value.InvoiceNumber, Number = value.Number.ToOptionalInt(), NumberPre = value.NumberPre, NumberLength = int.Parse(value.NumberLength, CultureInfo.InvariantCulture), Title = value.Title, Date = DateTime.Parse(value.Date, CultureInfo.InvariantCulture), Address = value.Address, Label = value.Label, Intro = value.Intro, Note = value.Note, TotalGross = float.Parse(value.TotalGross, CultureInfo.InvariantCulture), TotalNet = float.Parse(value.TotalNet, CultureInfo.InvariantCulture), CurrencyCode = value.CurrencyCode, TotalGrossUnreduced = float.Parse(value.TotalGrossUnreduced, CultureInfo.InvariantCulture), TotalNetUnreduced = float.Parse(value.TotalNetUnreduced, CultureInfo.InvariantCulture), Created = DateTime.Parse(value.Created, CultureInfo.InvariantCulture), DueDate = DateTime.Parse(value.DueDate, CultureInfo.InvariantCulture), DueDays = int.Parse(value.DueDays, CultureInfo.InvariantCulture), NetGross = netGrossType, SupplyDate = supplyDate, SupplyDateType = supplyDateType, Status = status, PaymentTypes = value.PaymentTypes.ToStringList(), Taxes = value.Taxes.ToDomain(), Quote = float.Parse(value.Quote, CultureInfo.InvariantCulture), Reduction = reduction, DiscountRate = float.Parse(value.DiscountRate, CultureInfo.InvariantCulture), DiscountDate = value.DiscountDate.ToOptionalDateTime(), DiscountDays = value.DiscountDays.ToOptionalInt(), DiscountAmount = value.DiscountAmount.ToOptionalFloat(), PaidAmount = value.PaidAmount.ToOptionalFloat() ?? 0, OpenAmount = float.Parse(value.OpenAmount, CultureInfo.InvariantCulture) }); }