Ejemplo n.º 1
0
        // PUT: api/QBDInventoryItems/5
        public IHttpActionResult PutQBDInventoryItem(long id, [FromBody] QBDInventoryItem inventoryItem)
        {
            var currentUser = CurrentUser();

            // Ensure that user is authorized.
            if (!currentUser.CanModifyInventoryItems)
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }

            var entity = _context.QBDInventoryItems
                         .Where(c => c.OrganizationId == currentUser.OrganizationId)
                         .Where(c => c.Id == id)
                         .FirstOrDefault();

            if (entity == null)
            {
                return(NotFound());
            }

            entity.CustomBarCodeValue = inventoryItem.CustomBarCodeValue;

            _context.SaveChanges();

            return(Ok());
        }
        public async Task <(bool, string)> SaveQBDInventoryItemAsync(QBDInventoryItem inventoryItem)
        {
            using (var request = new HttpRequestMessage(HttpMethod.Put, $"api/QBDInventoryItems/{inventoryItem.Id}"))
            {
                var payload = new Dictionary <string, object>()
                {
                    { "CustomBarCodeValue", inventoryItem.CustomBarCodeValue }
                };

                var json = JsonSerializer.Serialize(payload, options);

                using (var stringContent = new StringContent(json, Encoding.UTF8, "application/json"))
                {
                    request.Content = stringContent;

                    using (var response = await _apiService
                                          .GetHttpClient()
                                          .SendAsync(request, HttpCompletionOption.ResponseHeadersRead)
                                          .ConfigureAwait(false))
                    {
                        using var responseContent = await response.Content.ReadAsStreamAsync();

                        if (response.IsSuccessStatusCode)
                        {
                            if (response.StatusCode == HttpStatusCode.OK)
                            {
                                return(true, "");
                            }
                            else
                            {
                                return(false, responseContent.ToString());
                            }
                        }
                        else
                        {
                            return(false, responseContent.ToString());
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void Prepare()
        {
            try
            {
                // ----------------------------------------------------------------
                // Scaffold an organization.
                // ----------------------------------------------------------------

                var organization = new Organization()
                {
                    CreatedAt             = DateTime.UtcNow,
                    Name                  = "Test Organization",
                    Code                  = "1234",
                    StripeCustomerId      = "BLANK",
                    StripeSubscriptionId  = "BLANK",
                    SortCustomersByColumn = "Number",
                    SortProjectsByColumn  = "Number",
                    SortTasksByColumn     = "Number",
                    ShowCustomerNumber    = true,
                    ShowProjectNumber     = true,
                    ShowTaskNumber        = true
                };
                _context.Organizations.Add(organization);
                _context.SaveChanges();

                // ----------------------------------------------------------------
                // Scaffold a user.
                // ----------------------------------------------------------------

                var user = new User()
                {
                    CreatedAt           = DateTime.UtcNow,
                    EmailAddress        = "*****@*****.**",
                    Name                = "Test User A",
                    OrganizationId      = organization.Id,
                    IsDeleted           = false,
                    IsActive            = true,
                    Pin                 = "0000",
                    Role                = "Standard",
                    TimeZone            = "America/New_York",
                    AllowedPhoneNumbers = "*",
                    UsesTouchToneClock  = true,
                    CanCreateUsers      = true,
                    CanDeleteUsers      = true,
                    CanModifyUsers      = true,
                    CanViewUsers        = true,
                    CanCreateCustomers  = true,
                    CanDeleteCustomers  = true,
                    CanModifyCustomers  = true,
                    CanViewCustomers    = true,
                    CanCreateProjects   = true,
                    CanDeleteProjects   = true,
                    CanModifyProjects   = true,
                    CanViewProjects     = true,
                    CanCreateTasks      = true,
                    CanDeleteTasks      = true,
                    CanModifyTasks      = true,
                    CanViewTasks        = true,
                    CanCreateRates      = true,
                    CanDeleteRates      = true,
                    CanModifyRates      = true,
                    CanViewRates        = true,
                    CanCreateLocks      = true,
                    CanUndoLocks        = true,
                    CanViewLocks        = true,
                    CanCreatePunches    = true,
                    CanDeletePunches    = true,
                    CanModifyPunches    = true,
                    CanViewPunches      = true
                };
                _context.Users.Add(user);
                _context.SaveChanges();


                // ----------------------------------------------------------------
                // Scaffold a customer.
                // ----------------------------------------------------------------

                var customer = new Customer()
                {
                    CreatedAt      = DateTime.UtcNow,
                    Number         = "1000",
                    Name           = "General Electric",
                    OrganizationId = organization.Id
                };
                _context.Customers.Add(customer);
                _context.SaveChanges();


                // ----------------------------------------------------------------
                // Scaffold a project.
                // ----------------------------------------------------------------

                var customerId = _context.Customers
                                 .Where(c => c.Name == "General Electric")
                                 .Select(c => c.Id)
                                 .FirstOrDefault();
                var project = new Job()
                {
                    CreatedAt             = DateTime.UtcNow,
                    Number                = "1000",
                    Name                  = "Install Motor",
                    QuickBooksCustomerJob = "",
                    QuickBooksClass       = "",
                    CustomerId            = customerId,
                    Status                = "Open"
                };
                _context.Jobs.Add(project);
                _context.SaveChanges();


                // ----------------------------------------------------------------
                // Scaffold a task.
                // ----------------------------------------------------------------

                var jobId = _context.Jobs
                            .Where(j => j.Name == "Install Motor")
                            .Select(j => j.Id)
                            .FirstOrDefault();
                var task = new Task()
                {
                    CreatedAt = DateTime.UtcNow,
                    Number    = "1000",
                    Name      = "Installation",
                    JobId     = jobId
                };
                _context.Tasks.Add(task);
                _context.SaveChanges();


                // ----------------------------------------------------------------
                // Scaffold a punch.
                // ----------------------------------------------------------------

                var punch = new Punch()
                {
                    CreatedAt = DateTime.UtcNow,
                    TaskId    = task.Id,
                    InAt      = new DateTime(2022, 1, 1, 8, 0, 0),
                    OutAt     = new DateTime(2022, 1, 1, 17, 0, 0),
                    Guid      = Guid.NewGuid(),
                    UserId    = user.Id
                };
                _context.Punches.Add(punch);
                _context.SaveChanges();


                // ----------------------------------------------------------------
                // Scaffold an inventory item sync.
                // ----------------------------------------------------------------

                var inventoryItemSync = new QBDInventoryItemSync()
                {
                    OrganizationId            = organization.Id,
                    CreatedAt                 = DateTime.UtcNow,
                    CreatedByUserId           = user.Id,
                    Hostname                  = "HOSTNAME-01",
                    HostCompanyFileName       = "COMPANY FILE NAME",
                    HostCompanyFilePath       = "PATH TO FILE",
                    HostCountry               = "US",
                    HostMajorVersion          = "1",
                    HostMinorVersion          = "0",
                    HostProductName           = "PRODUCT NAME",
                    HostSupportedQBXMLVersion = "12"
                };
                _context.QBDInventoryItemSyncs.Add(inventoryItemSync);
                _context.SaveChanges();


                // ----------------------------------------------------------------
                // Scaffold an inventory item.
                // ----------------------------------------------------------------

                var inventoryItem = new QBDInventoryItem()
                {
                    ListId                 = "019F79CACE27HDKDUD32",
                    Name                   = "25-ft 12/2 Solid NM",
                    FullName               = "25-ft 12/2 Solid NM",
                    PurchaseCost           = 38.49m,
                    PurchaseDescription    = "Romex SIMpull 25-ft 12/2 Solid Non-Metallic Wire (By-the-Roll)",
                    SalesPrice             = 48.11m,
                    SalesDescription       = "Romex SIMpull 25-ft 12/2 Solid Non-Metallic Wire (By-the-Roll)",
                    BarCodeValue           = "70012",
                    CustomBarCodeValue     = "70012",
                    OrganizationId         = organization.Id,
                    ManufacturerPartNumber = "28828221",
                    QBDInventoryItemSyncId = inventoryItemSync.Id
                };
                _context.QBDInventoryItems.Add(inventoryItem);
                _context.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                Trace.TraceError(ex.ToString());
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }
        }