public async Task <byte[]> GetProjectThumbnailAsync(string userId, Guid projectId, int thumbnailSize) { using var log = BeginFunction(nameof(ProjectUserService), nameof(GetProjectThumbnailAsync), userId, projectId, thumbnailSize); try { await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); var entry = await ProjectMicroService.GetProjectAsync(projectId).ConfigureAwait(false); var kit = ProjectLibraryKitUtility.CreateKit(entry); var renderer = new DesignRenderer(); using var image = renderer.CreateBitmap(kit, thumbnailSize); using var ms = new MemoryStream(); image.Save(ms, ImageFormat.Png); var result = ms.ToArray(); log.Result(string.Format("byte[{0}]", result.Length)); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <UProject_ProjectSummaryList> GetProjectSummariesAsync(string userId, int?skip, int?take) { using var log = BeginFunction(nameof(ProjectUserService), nameof(GetProjectSummariesAsync), userId, skip, take); try { await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); var ownerReference = CreateOwnerReference.FromUserId(userId); var ownerId = await ProjectMicroService.AllocateOwnerAsync(ownerReference).ConfigureAwait(false); var entries = await ProjectMicroService.GetProjectsAsync(ownerId, skip, take).ConfigureAwait(false); var hasDeletedProjects = await ProjectMicroService.HasDeletedProjectsAsync(ownerId).ConfigureAwait(false); var summaries = Create.UProject_ProjectSummaries(entries); var result = new UProject_ProjectSummaryList() { ProjectSummaries = summaries, HasDeletedProjects = hasDeletedProjects }; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <bool> AddProjectAsync(string userId, Guid projectId, int quantity) { using var log = BeginFunction(nameof(CartUserService), nameof(AddProjectAsync), userId, projectId, quantity); try { await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); var ordererReference = CreateOrdererReference.FromUserId(userId); var ordererId = await OrderMicroService.AllocateOrdererAsync(ordererReference).ConfigureAwait(false); var projectSnapshotId = await ProjectMicroService.GetCurrentSnapshotIdAsync(projectId).ConfigureAwait(false); var mProjectSnapshotDetail = await ProjectMicroService.GetProjectSnapshotAsync(projectSnapshotId).ConfigureAwait(false); var mAllocateOrderable = MicroDataFactory.MOrder_AllocateOrderable(mProjectSnapshotDetail); var mAllocateOrderableResponseData = await OrderMicroService.AllocateOrderableAsync(mAllocateOrderable).ConfigureAwait(false); var orderableId = mAllocateOrderableResponseData.OrderableId; var result = await OrderMicroService.AddCartItemAsync(ordererId, orderableId, quantity).ConfigureAwait(false); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task CreateProject() { var logger = ServiceScope.ServiceProvider.GetService <ILogger <ProjectTest> >(); // Get the user ID. // string userId; { var identityUser = await UserManager.FindByNameAsync("*****@*****.**"); userId = identityUser.Id; logger.LogInformation("UserId = {0}", userId); } // Create the design. // Guid designId; { var designData = Factory.CreateDesign(); designId = await DesignAjaxService.SaveDesignAsync(userId, designData); logger.LogInformation($"Design ID = {designId}"); } // Create the project. // string projectId; { projectId = await ProjectUserService.CreateProjectAsync(userId, ProjectUserService.ProjectType_Kit, "Test Project", designId); logger.LogInformation($"Project ID = {projectId}"); } // Create the orderable ID. // long orderableId; { var projectSnapshotId = await ProjectMicroService.GetCurrentSnapshotIdAsync(Guid.Parse(projectId)); var mProjectSnapshotDetail = await ProjectMicroService.GetProjectSnapshotAsync(projectSnapshotId); var mAllocateOrderable = MicroDataFactory.MOrder_AllocateOrderable(mProjectSnapshotDetail); var mAllocateOrderableResponseData = await OrderMicroService.AllocateOrderableAsync(mAllocateOrderable); orderableId = mAllocateOrderableResponseData.OrderableId; logger.LogInformation($"Orderable ID = {orderableId}"); } }
public async Task <bool> DeleteProjectAsync(string userId, Guid projectId) { using var log = BeginFunction(nameof(ProjectUserService), nameof(DeleteProjectAsync), userId, projectId); try { await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); var result = await ProjectMicroService.DeleteProjectAsync(projectId, GetUtcNow()).ConfigureAwait(false); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <Guid?> UndeleteProjectAsync(string userId) { using var log = BeginFunction(nameof(ProjectUserService), nameof(UndeleteProjectAsync), userId); try { await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); var ownerReference = CreateOwnerReference.FromUserId(userId); var ownerId = await ProjectMicroService.AllocateOwnerAsync(ownerReference).ConfigureAwait(false); var result = await ProjectMicroService.UndeleteProjectAsync(ownerId, GetUtcNow()).ConfigureAwait(false); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <string> CreateProjectAsync(string userId, string projectType, string projectName, Guid designId) { using var log = BeginFunction(nameof(ProjectUserService), nameof(CreateProjectAsync), projectType, userId, projectName, designId); try { await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); string result; if (projectType == ProjectType_Kit) { var mDesign = await DesignMicroService.GetDesignAsync(designId).ConfigureAwait(false); var design = new Design.Core.Design(JToken.Parse(mDesign.DesignArtifactValue)); var projectData = ProjectLibraryKitUtility.CreateProjectSpecification(design); var ownerReference = CreateOwnerReference.FromUserId(userId); var ownerId = await ProjectMicroService.AllocateOwnerAsync(ownerReference).ConfigureAwait(false); var id = await ProjectMicroService.CreateProjectAsync(ownerId, projectName, ProjectTypeCodes.Kit, mDesign.DesignSnapshotId, projectData, GetUtcNow()).ConfigureAwait(false); result = id.ToString(); } else { throw new ArgumentException(string.Format("Unknown projectType {0}", projectType), nameof(projectType)); } log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <ADashboard_Summary> GetDashboardDataAsync() { using var log = BeginFunction(nameof(DashboardAdminService), nameof(GetDashboardDataAsync)); try { await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false); var result = new ADashboard_Summary() { MCommunication_Dashboard = await CommunicationMicroService.GetDashboardAsync(), MDesign_Dashboard = await DesignMicroService.GetDashboardAsync(), MFulfillment_Dashboard = await FulfillmentMicroService.GetDashboardAsync(), MFunding_Dashboard = await FundingMicroService.GetDashboardAsync(), MLedger_Dashboard = await LedgerMicroService.GetDashboardAsync(), MOrder_Dashboard = await OrderMicroService.GetDashboardAsync(), MProject_Dashboard = await ProjectMicroService.GetDashboardAsync(), MSquare_Dashboard = await SquareMicroService.GetDashboardAsync(), MUser_Dashboard = await UserMicroService.GetDashboardAsync() }; //using (var ctx = QuiltContextFactory.Create()) //{ // using var conn = QuiltContextFactory.CreateConnection(); // conn.Open(); // // Order // // // { // var statusCounts = new List<Admin_Dashboard_StatusCountData>(); // foreach (var dbOrder in GetDashboardOrders(conn).ToList()) // { // var statusCount = new Admin_Dashboard_StatusCountData() // { // StatusName = ctx.OrderStatusType(dbOrder.OrderStatusTypeCode).Name, // Count = dbOrder.RecordCount.GetValueOrDefault() // }; // statusCounts.Add(statusCount); // } // result.OrderStatusCounts = statusCounts; // } // // Order Return Request // // // { // var statusCounts = new List<Admin_Dashboard_StatusCountData>(); // foreach (var dbOrderReturnRequest in GetDashboardOrderReturnRequests(conn).ToList()) // { // var statusCount = new Admin_Dashboard_StatusCountData() // { // StatusName = ctx.ReturnRequestStatusType(dbOrderReturnRequest.OrderReturnRequestStatusTypeCode).Name, // Count = dbOrderReturnRequest.RecordCount.GetValueOrDefault() // }; // statusCounts.Add(statusCount); // } // result.OrderReturnRequestStatusCounts = statusCounts; // } // // Order Return // // // { // var statusCounts = new List<Admin_Dashboard_StatusCountData>(); // foreach (var dbOrderReturn in GetDashboardOrderReturns(conn).ToList()) // { // var statusCount = new Admin_Dashboard_StatusCountData() // { // StatusName = ctx.ReturnStatusType(dbOrderReturn.OrderReturnStatusTypeCode).Name, // Count = dbOrderReturn.RecordCount.GetValueOrDefault() // }; // statusCounts.Add(statusCount); // } // result.OrderReturnStatusCounts = statusCounts; // } // // Order Shipment Request // // // { // var statusCounts = new List<Admin_Dashboard_StatusCountData>(); // foreach (var dbOrderShipmentRequest in GetDashboardOrderShipmentRequests(conn).ToList()) // { // var statusCount = new Admin_Dashboard_StatusCountData() // { // StatusName = ctx.ShipmentRequestStatusType(dbOrderShipmentRequest.OrderShipmentRequestStatusTypeCode).Name, // Count = dbOrderShipmentRequest.RecordCount.GetValueOrDefault() // }; // statusCounts.Add(statusCount); // } // result.OrderShipmentRequestStatusCounts = statusCounts; // } // // Order Shipment // // // { // var statusCounts = new List<Admin_Dashboard_StatusCountData>(); // foreach (var dbOrderShipment in GetDashboardOrderShipments(conn).ToList()) // { // var statusCount = new Admin_Dashboard_StatusCountData() // { // StatusName = ctx.ShipmentStatusType(dbOrderShipment.OrderShipmentStatusTypeCode).Name, // Count = dbOrderShipment.RecordCount.GetValueOrDefault() // }; // statusCounts.Add(statusCount); // } // result.OrderShipmentStatusCounts = statusCounts; // } //} log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task CreateAndShipOrder() { var services = ServiceScope.ServiceProvider; var logger = services.GetService <ILogger <OrderTest> >(); var unitOfWork = CreateUnitOfWork.Timestamp(GetUniqueNow()); // Get the user ID. // string userId; { var identityUser = await UserManager.FindByNameAsync("*****@*****.**"); userId = identityUser.Id; logger.LogInformation("User ID = {0}", userId); } // Get the orderer ID. // long ordererId; { var ordererReference = CreateOrdererReference.FromTimestamp(GetUniqueNow()); ordererId = await OrderMicroService.AllocateOrdererAsync(ordererReference); logger.LogInformation("Orderer ID = {0}", ordererId); } // Get the funder ID. // long funderId; { var funderReference = CreateFunderReference.FromTimestamp(GetUniqueNow()); funderId = await FundingMicroService.AllocateFunderAsync(funderReference); logger.LogInformation("Funder ID = {0}", funderId); } // Create the design. // Guid designId; { var designData = Factory.CreateDesign(); designId = await DesignAjaxService.SaveDesignAsync(userId, designData); logger.LogInformation($"Design ID = {designId}"); } // Create the project. // string projectId; { projectId = await ProjectUserService.CreateProjectAsync(userId, ProjectUserService.ProjectType_Kit, "Test Project", designId); logger.LogInformation($"Project ID = {projectId}"); } // Create the orderable ID. // long orderableId; { var projectSnapshotId = await ProjectMicroService.GetCurrentSnapshotIdAsync(Guid.Parse(projectId)); var mProjectSnapshotDetail = await ProjectMicroService.GetProjectSnapshotAsync(projectSnapshotId); var mAllocateOrderable = MicroDataFactory.MOrder_AllocateOrderable(mProjectSnapshotDetail); var mAllocateOrderableResponseData = await OrderMicroService.AllocateOrderableAsync(mAllocateOrderable); orderableId = mAllocateOrderableResponseData.OrderableId; logger.LogInformation($"Orderable ID = {orderableId}"); } var shippingAddress = new MCommon_Address() { Name = "RICH TODD", AddressLine1 = "17340 W 156 TER", City = "OLATHE", StateCode = "KS", PostalCode = "66062", CountryCode = "US" }; // Create the order. // long orderId; { // Add item to cart. // _ = await OrderMicroService.AddCartItemAsync(ordererId, orderableId, 2); // Update shipping address. // _ = await OrderMicroService.UpdateShippingAddressAsync(ordererId, shippingAddress); // Submit order. // orderId = await OrderMicroService.SubmitCartAsync(ordererId); logger.LogInformation($"Order ID = {orderId}"); } _ = await EventProcessorMicroService.ProcessPendingEvents(); // Create fundable for order. // long fundableId; { var fundableReference = CreateFundableReference.FromOrderId(orderId); fundableId = await FundingMicroService.AllocateFundableAsync(fundableReference); logger.LogInformation($"Fundable ID = {fundableId}"); } // Retrieve the fundable detail. // MFunding_Fundable fundableDetail; { fundableDetail = await FundingMicroService.GetFundableAsync(fundableId); logger.LogInformation($"Fundable Detail = {fundableDetail}"); } // Post a receipt for the order. // { var fundsRequiredDelta = fundableDetail.FundsRequiredTotal - fundableDetail.FundsReceived; await FundingMicroService.SetFundsReceivedAsync(funderId, fundableDetail.FundableReference, fundableDetail.FundsRequiredTotal, unitOfWork.Next()); //await fundingService.TransferFundsAsync(funderId, fundableId, fundsRequiredDelta); logger.LogInformation($"{fundsRequiredDelta} funds applied."); } _ = await EventProcessorMicroService.ProcessPendingEvents(); // Lookup fulfillable. // long fulfillableId; { var fulfillableReference = CreateFulfillableReference.FromOrderId(orderId); fulfillableId = (await FulfillmentMicroService.LookupFulfillableAsync(fulfillableReference)).Value; await FulfillmentMicroService.SetFulfillableShippingAddress(fulfillableId, shippingAddress); logger.LogInformation($"Fulfillable ID = {fulfillableId}"); } // Lookup pending shipment request. // long?shipmentRequestId; { shipmentRequestId = await FulfillmentMicroService.GetPendingShipmentRequestAsync(fulfillableId); logger.LogInformation($"Shipment Request ID = {shipmentRequestId}"); } // Open it. // { await FulfillmentMicroService.OpenShipmentRequestAsync(shipmentRequestId.Value); } // Lookup shipment request. // MFulfillment_ShipmentRequest shipmentRequestDetail; { shipmentRequestDetail = await FulfillmentMicroService.GetShipmentRequestAsync(shipmentRequestId.Value); logger.LogInformation($"Shipment Request Detail = {shipmentRequestDetail}"); } // Create shipment. // long shipmentId; { var items = new List <MFulfillment_CreateShipmentItem>(); foreach (var shipmentRequestItemDetail in shipmentRequestDetail.ShipmentRequestItems) { items.Add(new MFulfillment_CreateShipmentItem() { ShipmentRequestItemId = shipmentRequestItemDetail.ShipmentRequestItemId, Quantity = shipmentRequestItemDetail.Quantity }); } var data = new MFulfillment_CreateShipment() { ShippingVendorId = ShippingVendorIds.Usps, ShipmentDateTimeUtc = Locale.GetUtcNow(), TrackingCode = "123123", CreateShipmentItems = items }; shipmentId = await FulfillmentMicroService.CreateShipmentAsync(data); await FulfillmentMicroService.PostShipmentAsync(shipmentId); await FulfillmentMicroService.ProcessShipmentAsync(shipmentId); logger.LogInformation($"Shipment ID = {shipmentId}"); } _ = await EventProcessorMicroService.ProcessPendingEvents(); }
public async Task CreateOrder() { var services = ServiceScope.ServiceProvider; var logger = services.GetService <ILogger <OrderTest> >(); var unitOfWork = CreateUnitOfWork.Timestamp(GetUniqueNow()); // Get the user ID. // string userId; { var identityUser = await UserManager.FindByNameAsync("*****@*****.**"); userId = identityUser.Id; logger.LogInformation("User ID = {0}", userId); } // Get the orderer ID. // long ordererId; { var ordererReference = CreateOrdererReference.FromTimestamp(GetUniqueNow()); ordererId = await OrderMicroService.AllocateOrdererAsync(ordererReference); logger.LogInformation("Orderer ID = {0}", ordererId); } // Get the funder ID. // long funderId; { var funderReference = CreateFunderReference.FromTimestamp(GetUniqueNow()); funderId = await FundingMicroService.AllocateFunderAsync(funderReference); logger.LogInformation("Funder ID = {0}", funderId); } // Create the design. // Guid designId; { var designData = Factory.CreateDesign(); designId = await DesignAjaxService.SaveDesignAsync(userId, designData); logger.LogInformation($"Design ID = {designId}"); } for (int idx = 0; idx < 3; ++idx) { // Create the project. // string projectId; { projectId = await ProjectUserService.CreateProjectAsync(userId, ProjectUserService.ProjectType_Kit, "Test Project", designId); logger.LogInformation($"Project ID = {projectId}"); } // Create the orderable ID. // long orderableId; { var projectSnapshotId = await ProjectMicroService.GetCurrentSnapshotIdAsync(Guid.Parse(projectId)); var mProjectSnapshotDetail = await ProjectMicroService.GetProjectSnapshotAsync(projectSnapshotId); var mAllocateOrderable = MicroDataFactory.MOrder_AllocateOrderable(mProjectSnapshotDetail); var mAllocateOrderableResponseData = await OrderMicroService.AllocateOrderableAsync(mAllocateOrderable); orderableId = mAllocateOrderableResponseData.OrderableId; logger.LogInformation($"Orderable ID = {orderableId}"); } // Add orderable to cart // { // Add item to cart. // _ = await OrderMicroService.AddCartItemAsync(ordererId, orderableId, (idx + 1) * 2); } } var shippingAddress = new MCommon_Address() { Name = "RICH TODD", AddressLine1 = "17340 W 156 TER", City = "OLATHE", StateCode = "KS", PostalCode = "66062", CountryCode = "US" }; // Create the order. // long orderId; { // Update shipping address. // _ = await OrderMicroService.UpdateShippingAddressAsync(ordererId, shippingAddress); // Submit order. // orderId = await OrderMicroService.SubmitCartAsync(ordererId); logger.LogInformation($"Order ID = {orderId}"); } _ = await EventProcessorMicroService.ProcessPendingEvents(); // Create fundable for order. // long fundableId; { var fundableReference = CreateFundableReference.FromOrderId(orderId); fundableId = await FundingMicroService.AllocateFundableAsync(fundableReference); logger.LogInformation($"Fundable ID = {fundableId}"); } // Retrieve the fundable detail. // MFunding_Fundable fundableDetail; { fundableDetail = await FundingMicroService.GetFundableAsync(fundableId); logger.LogInformation($"Fundable Detail = {fundableDetail}"); } // Post a receipt for the order. // { var fundsRequiredDelta = fundableDetail.FundsRequiredTotal - fundableDetail.FundsReceived; await FundingMicroService.SetFundsReceivedAsync(funderId, fundableDetail.FundableReference, fundableDetail.FundsRequiredTotal, unitOfWork.Next()); //await fundingService.TransferFundsAsync(funderId, fundableId, fundsRequiredDelta); logger.LogInformation($"{fundsRequiredDelta} funds applied."); } _ = await EventProcessorMicroService.ProcessPendingEvents(); }