private static DatabaseResourceLibrary Create(IQuiltContextFactory quiltContextFactory, string name) { using var ctx = quiltContextFactory.Create(); var dbResourceLibrary = ctx.ResourceLibraries.Where(r => r.Name == name).SingleOrDefault(); if (dbResourceLibrary == null) { dbResourceLibrary = new ResourceLibrary() { Name = name }; _ = ctx.ResourceLibraries.Add(dbResourceLibrary); _ = ctx.SaveChanges(); } return(new DatabaseResourceLibrary(quiltContextFactory, dbResourceLibrary.ResourceLibraryId, name)); }
private static void CreateTestAccountingYears(IQuiltContextFactory quiltContextFactory) { using var ctx = quiltContextFactory.Create(); var year = DateTime.Now.Year; var dbAccountingYear = ctx.AccountingYears.Where(r => r.Year == year).SingleOrDefault(); if (dbAccountingYear == null) { dbAccountingYear = new AccountingYear() { Year = year, AccountingYearStatusCode = AccountingYearStatusTypeCodes.Open }; _ = ctx.AccountingYears.Add(dbAccountingYear); _ = ctx.SaveChanges(); } }
private static void CreateTestLedgerAccountTransactions(IQuiltContextFactory quiltContextFactory, DateTime utcNow, DateTime localNow) { using var ctx = quiltContextFactory.Create(); var unitOfWork = new UnitOfWork("TEMP"); var dbLedgerTransaction = ctx.LedgerTransactions.Where(r => r.Description == TestLedgerAccountTransactionDescription).SingleOrDefault(); if (dbLedgerTransaction == null) { _ = ctx.CreateLedgerAccountTransactionBuilder() .Begin(TestLedgerAccountTransactionDescription, localNow, utcNow) .UnitOfWork(unitOfWork) .Debit(LedgerAccountNumbers.Cash, 50000.00m) .Credit(LedgerAccountNumbers.OwnersEquity, 50000.00m) .Create(); _ = ctx.SaveChanges(); } }
public async Task <byte[]> Print(string userId) { const double fontSize = 16; var font = new XFont("carrois gothic regular", fontSize, XFontStyle.Regular); var document = new PdfDocument(); document.Info.Title = "Font Resolver Sample"; var page = document.AddPage(); var gfx = XGraphics.FromPdfPage(page); var tf = new XTextFormatter(gfx); //int y = 0; using (var ctx = m_quiltContextFactory.Create()) { var dbOrders = await ctx.Orders.ToListAsync().ConfigureAwait(false); foreach (var dbOrder in dbOrders) { //var order = factory.Create_Order_CartData(dbOrder, designLibrary); //foreach (var item in order.Items) //{ // //XImage image; // //using (var ms = new MemoryStream(item.Image.Image)) // //{ // // image = XImage.FromStream(ms); // //} // //gfx.DrawImage(image, 72, y); // y += 72 * 2; //} } } using var stream = new MemoryStream(); document.Save(stream); return(stream.ToArray()); }
private string GetTimeZoneId(HttpContext httpContext) { var userId = httpContext.GetUserId(); if (!string.IsNullOrEmpty(userId)) { using var ctx = m_quiltContextFactory.Create(); var dbAspNetUser = ctx.AspNetUsers.Where(r => r.Id == userId).SingleOrDefault(); if (dbAspNetUser != null) { var dbUserProfile = dbAspNetUser.UserProfileAspNetUsers.SingleOrDefault()?.UserProfile; if (dbUserProfile != null && !string.IsNullOrEmpty(dbUserProfile.TimeZoneId)) { return(dbUserProfile.TimeZoneId); } } } return(TimeZoneInfo.Local.Id); }
private static void CreateStandardDomains(IQuiltContextFactory quiltContextFactory) { using var ctx = quiltContextFactory.Create(); CreateAccountingYearStatusType(ctx, AccountingYearStatusTypeCodes.Open, "Open"); CreateAddressType(ctx, AddressTypeCodes.Shipping, "Shipping"); CreateAlertType(ctx, AlertTypeCodes.OperationException, "Operation Exception"); CreateAlertType(ctx, AlertTypeCodes.OrderReceipt, "Order Receipt"); CreateAlertType(ctx, AlertTypeCodes.OrderReceiptFailure, "Order Receipt Failure"); CreateAlertType(ctx, AlertTypeCodes.OrderReceiptMismatch, "Order Receipt Mismatch"); CreateAlertType(ctx, AlertTypeCodes.OrderPaymentMismatch, "Order Payment Mismatch"); CreateAlertType(ctx, AlertTypeCodes.PayPalIpnFailure, "PayPal Failure"); CreateAlertType(ctx, AlertTypeCodes.PayPalIpnSuccess, "PayPal Success"); CreateAlertType(ctx, AlertTypeCodes.UnexpectedOrderPayment, "Unexpected Order Payment"); CreateArtifactType(ctx, ArtifactTypeCodes.Component, "Component"); CreateArtifactType(ctx, ArtifactTypeCodes.Design, "Design"); CreateArtifactType(ctx, ArtifactTypeCodes.Kit, "Kit"); CreateArtifactValueType(ctx, ArtifactValueTypeCodes.Json, "JSON"); CreateInventoryItemType(ctx, InventoryItemTypeCodes.Fabric, "Fabric"); // 1XXX - Assets (Debit) CreateLedgerAccount(ctx, LedgerAccountNumbers.Cash, "Cash", LedgerAccountCodes.Debit); CreateLedgerAccount(ctx, LedgerAccountNumbers.AccountReceivable, "Account Receivable", LedgerAccountCodes.Debit); CreateLedgerAccount(ctx, LedgerAccountNumbers.SalesTaxReceivable, "Sales Tax Receivable", LedgerAccountCodes.Debit); CreateLedgerAccount(ctx, LedgerAccountNumbers.FabricSupplyAsset, "Fabric Supply Asset", LedgerAccountCodes.Debit); CreateLedgerAccount(ctx, LedgerAccountNumbers.FabricSupplySuspense, "Fabric Supply Suspense", LedgerAccountCodes.Debit); // 2XXX - Liabilities (Credit) CreateLedgerAccount(ctx, LedgerAccountNumbers.AccountPayable, "Account Payable", LedgerAccountCodes.Credit); CreateLedgerAccount(ctx, LedgerAccountNumbers.SalesTaxPayable, "Sales Tax Payable", LedgerAccountCodes.Credit); CreateLedgerAccount(ctx, LedgerAccountNumbers.FundsSuspense, "Funds Suspense", LedgerAccountCodes.Credit); // 3XXX - Equity(Credit) CreateLedgerAccount(ctx, LedgerAccountNumbers.OwnersEquity, "Owners Equity", LedgerAccountCodes.Credit); // 4XXX - Income (Credit) CreateLedgerAccount(ctx, LedgerAccountNumbers.Income, "Income", LedgerAccountCodes.Credit); // 5XXX - Expense (Debit) CreateLedgerAccount(ctx, LedgerAccountNumbers.PaymentFeeExpense, "Payment Fee Expense", LedgerAccountCodes.Debit); CreateLedgerAccount(ctx, LedgerAccountNumbers.FabricSupplyExpense, "Fabric Supply Expense", LedgerAccountCodes.Debit); CreateLogEntryType(ctx, LogEntryTypeCodes.Controller, "Controller"); CreateLogEntryType(ctx, LogEntryTypeCodes.Job, "Job"); CreateLogEntryType(ctx, LogEntryTypeCodes.Service, "Service"); CreateNotificationType(ctx, NotificationTypeCodes.OrderShipped, "Order Shipped", "Your order has shipped", Resources.OrderShippedNotification, "text/plain"); CreateNotificationType(ctx, NotificationTypeCodes.OrderShipping, "Order Shipping", "Your order is being processed", Resources.OrderShippingNotification, "text/plain"); CreateNotificationType(ctx, NotificationTypeCodes.RefundIssued, "Refund Issued", "A refund for your order has been issued", Resources.RefundIssuedNotification, "text/plain"); CreateOrderStatusType(ctx, OrderStatusCodes.Pending, "PENDING"); CreateOrderStatusType(ctx, OrderStatusCodes.Submitted, "SUBMITTED"); CreateOrderStatusType(ctx, OrderStatusCodes.Fulfilling, "FULFILLING"); CreateOrderStatusType(ctx, OrderStatusCodes.Closed, "CLOSED"); CreateReturnRequestReasonType(ctx, ReturnRequestReasonCodes.ItemNotOrdered, "Item not ordered", true, true, true, 0); CreateReturnRequestReasonType(ctx, ReturnRequestReasonCodes.ItemDefective, "Item defective", true, true, true, 0); CreateReturnRequestReasonType(ctx, ReturnRequestReasonCodes.ItemDamagedDuringShipping, "Item damaged during shipping", true, true, true, 0); CreateReturnRequestReasonType(ctx, ReturnRequestReasonCodes.NoLongerNeeded, "No longer needed", true, true, true, 0); CreateReturnRequestReasonType(ctx, ReturnRequestReasonCodes.ItemArrivedTooLate, "Item arrived too late", true, true, true, 0); CreateReturnRequestStatusType(ctx, ReturnRequestStatusCodes.Open, "Open"); CreateReturnRequestStatusType(ctx, ReturnRequestStatusCodes.Posted, "Posted"); CreateReturnRequestStatusType(ctx, ReturnRequestStatusCodes.Complete, "Complete"); CreateReturnRequestStatusType(ctx, ReturnRequestStatusCodes.Cancelled, "Cancelled"); CreateReturnRequestType(ctx, ReturnRequestTypeCodes.Manual, "Manual"); CreateReturnRequestType(ctx, ReturnRequestTypeCodes.Replace, "Replace"); CreateReturnRequestType(ctx, ReturnRequestTypeCodes.Return, "Return"); CreateReturnStatusType(ctx, ReturnStatusCodes.Open, "Open"); CreateReturnStatusType(ctx, ReturnStatusCodes.Posted, "Posted"); CreateReturnStatusType(ctx, ReturnStatusCodes.Complete, "Complete"); CreateReturnStatusType(ctx, ReturnStatusCodes.Cancelled, "Cancelled"); CreateShipmentRequestStatusType(ctx, ShipmentRequestStatusCodes.Pending, "Pending"); CreateShipmentRequestStatusType(ctx, ShipmentRequestStatusCodes.Open, "Open"); CreateShipmentRequestStatusType(ctx, ShipmentRequestStatusCodes.Complete, "Complete"); CreateShipmentRequestStatusType(ctx, ShipmentRequestStatusCodes.Cancelled, "Cancelled"); CreateShipmentRequestStatusType(ctx, ShipmentRequestStatusCodes.Exception, "Exception"); CreateShipmentStatusType(ctx, ShipmentStatusCodes.Open, "Open"); CreateShipmentStatusType(ctx, ShipmentStatusCodes.Posted, "Posted"); CreateShipmentStatusType(ctx, ShipmentStatusCodes.Complete, "Complete"); CreateShipmentStatusType(ctx, ShipmentStatusCodes.Cancelled, "Cancelled"); CreateShipmentStatusType(ctx, ShipmentStatusCodes.Exception, "Exception"); CreateOrderTransactionType(ctx, OrderTransactionTypeCodes.Submit, "Submit"); CreateOrderTransactionType(ctx, OrderTransactionTypeCodes.FundsReceived, "Funds Received"); CreateOrderTransactionType(ctx, OrderTransactionTypeCodes.FundsRequired, "Funds Required"); CreateOrderTransactionType(ctx, OrderTransactionTypeCodes.FulfillmentRequired, "Fulfillment Required"); CreateOrderTransactionType(ctx, OrderTransactionTypeCodes.FulfillmentComplete, "Fulfillment Complete"); CreateOrderTransactionType(ctx, OrderTransactionTypeCodes.FulfillmentReturn, "Fulfillment Return"); CreateOrderTransactionType(ctx, OrderTransactionTypeCodes.Close, "Close"); CreateProjectType(ctx, ProjectTypeCodes.Kit, "Kit"); CreateShippingVendor(ctx, ShippingVendorIds.FedEx, "FedEx"); CreateShippingVendor(ctx, ShippingVendorIds.Ups, "UPS"); CreateShippingVendor(ctx, ShippingVendorIds.Usps, "USPS"); CreateTagCategory(ctx, TagCategoryCodes.InventoryItem, "Inventory Item"); CreateTagCategory(ctx, TagCategoryCodes.Resource, "Resource"); CreateTagType(ctx, TagTypeCodes.Collection, TagCategoryCodes.InventoryItem, "Collection"); CreateTagType(ctx, TagTypeCodes.Manufacturer, TagCategoryCodes.InventoryItem, "Manufacturer"); CreateTagType(ctx, TagTypeCodes.Block, TagCategoryCodes.Resource, "Block"); CreateUnitOfMeasure(ctx, UnitOfMeasureCodes.FatQuarter, "Fat Quarter"); CreateUnitOfMeasure(ctx, UnitOfMeasureCodes.HalfYardage, "Half Yard"); CreateUnitOfMeasure(ctx, UnitOfMeasureCodes.Yardage, "Yard"); CreateUnitOfMeasure(ctx, UnitOfMeasureCodes.TwoYards, "Two Yard"); CreateUnitOfMeasure(ctx, UnitOfMeasureCodes.ThreeYards, "Three Yard"); _ = ctx.SaveChanges(); }
public static async Task <long> CreateEntryAsync(IQuiltContextFactory quiltContextFactory, string sku, string inventoryItemTypeCode, string name, string collection, string manufacturer, int hue, int saturation, int value, IEnumerable <string> unitOfMeasureCodes, string pricingScheduleName, DateTime utcNow) { using var ctx = quiltContextFactory.Create(); var dbPricingSchedule = ctx.PricingSchedules.Where(r => r.Name == pricingScheduleName).Single(); var dbCollectionTag = ctx.Tags.Where(r => r.TagTypeCode == TagTypeCodes.Collection && r.Value == collection).SingleOrDefault(); if (dbCollectionTag == null) { dbCollectionTag = new Tag() { TagTypeCodeNavigation = ctx.TagType(TagTypeCodes.Collection), Value = collection, CreateDateTimeUtc = utcNow }; _ = ctx.Tags.Add(dbCollectionTag); } var dbManufacturerTag = ctx.Tags.Where(r => r.TagTypeCode == TagTypeCodes.Manufacturer && r.Value == manufacturer).SingleOrDefault(); if (dbManufacturerTag == null) { dbManufacturerTag = new Tag() { TagTypeCodeNavigation = ctx.TagType(TagTypeCodes.Manufacturer), Value = manufacturer, CreateDateTimeUtc = utcNow }; _ = ctx.Tags.Add(dbManufacturerTag); } var dbInventoryItem = ctx.InventoryItems.Where(r => r.Sku == sku).SingleOrDefault(); if (dbInventoryItem == null) { dbInventoryItem = new InventoryItem() { Sku = sku, InventoryItemTypeCode = inventoryItemTypeCode, Name = name, Quantity = 0, ReservedQuantity = 0, Hue = hue, Saturation = saturation, Value = value, PricingSchedule = dbPricingSchedule }; _ = ctx.InventoryItems.Add(dbInventoryItem); } else { dbInventoryItem.InventoryItemTypeCode = inventoryItemTypeCode; dbInventoryItem.Name = name; //dbInventoryItem.Quantity //dbInventoryItem.ReservedQuantity dbInventoryItem.Hue = hue; dbInventoryItem.Saturation = saturation; dbInventoryItem.Value = value; dbInventoryItem.PricingSchedule = dbPricingSchedule; } var dbInventoryItemCollectionTag = dbInventoryItem.InventoryItemTags.Where(r => r.Tag.TagTypeCode == TagTypeCodes.Collection).SingleOrDefault(); if (dbInventoryItemCollectionTag == null) { dbInventoryItemCollectionTag = new InventoryItemTag() { InventoryItem = dbInventoryItem, Tag = dbCollectionTag, CreateDateTimeUtc = utcNow, }; _ = ctx.InventoryItemTags.Add(dbInventoryItemCollectionTag); } else { dbInventoryItemCollectionTag.Tag = dbCollectionTag; } var dbInventoryItemManufacturerTag = dbInventoryItem.InventoryItemTags.Where(r => r.Tag.TagTypeCode == TagTypeCodes.Manufacturer).SingleOrDefault(); if (dbInventoryItemManufacturerTag == null) { dbInventoryItemManufacturerTag = new InventoryItemTag() { InventoryItem = dbInventoryItem, Tag = dbManufacturerTag, CreateDateTimeUtc = utcNow }; _ = ctx.InventoryItemTags.Add(dbInventoryItemManufacturerTag); } else { dbInventoryItemManufacturerTag.Tag = dbManufacturerTag; } foreach (var unitOfMeasureCode in unitOfMeasureCodes) { var dbUnitOfMeasure = ctx.UnitOfMeasure(unitOfMeasureCode); if (!dbInventoryItem.InventoryItemUnits.Any(r => r.UnitOfMeasureCode == unitOfMeasureCode)) { var dbInventoryItemUnit = new InventoryItemUnit() { InventoryItem = dbInventoryItem, UnitOfMeasureCodeNavigation = dbUnitOfMeasure }; _ = ctx.InventoryItemUnits.Add(dbInventoryItemUnit); } } _ = await ctx.SaveChangesAsync().ConfigureAwait(false); return(dbInventoryItem.InventoryItemId); }