• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

samsmithnz / SatisfactoryTree / 17962523436

24 Sep 2025 12:22AM UTC coverage: 64.18% (-4.0%) from 68.215%
17962523436

Pull #314

github

web-flow
Merge c10995f91 into 9b5cf3f1d
Pull Request #314: Add "Add exported Part" button functionality to factory exported parts section

427 of 772 branches covered (55.31%)

Branch coverage included in aggregate %.

30 of 196 new or added lines in 8 files covered. (15.31%)

8 existing lines in 3 files now uncovered.

1173 of 1721 relevant lines covered (68.16%)

1085.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/SatisfactoryTree.Web/Services/PlanService.cs
1
using SatisfactoryTree.Logic.Models;
2

3
namespace SatisfactoryTree.Web.Services
4
{
5
    public class PlanService
6
    {
7
        private Plan? _plan;
8
        private FactoryCatalog? _factoryCatalog;
9
        
10
        public event Action? PlanChanged;
11

12
        public Plan? Plan 
13
        { 
14
            get => _plan; 
×
15
            set 
16
            { 
×
17
                _plan = value; 
×
18
                PlanChanged?.Invoke(); 
×
19
            } 
×
20
        }
21

22
        public FactoryCatalog? FactoryCatalog
23
        {
NEW
24
            get => _factoryCatalog;
×
NEW
25
            set => _factoryCatalog = value;
×
26
        }
27

UNCOV
28
        public bool HasPlan => _plan != null && _plan.Factories.Any();
×
29

30
        public void AddExportedPartToFactory(int factoryId, string itemName, double quantity)
NEW
31
        {
×
NEW
32
            if (_plan == null || _factoryCatalog == null)
×
NEW
33
                return;
×
34

NEW
35
            var factory = _plan.Factories.FirstOrDefault(f => f.Id == factoryId);
×
NEW
36
            if (factory == null)
×
NEW
37
                return;
×
38

39
            // Check if this exported part already exists
NEW
40
            var existingExport = factory.ExportedParts.FirstOrDefault(e => e.Item.Name == itemName);
×
NEW
41
            if (existingExport != null)
×
NEW
42
            {
×
43
                // Update existing quantity
NEW
44
                existingExport.Item.Quantity = quantity;
×
NEW
45
            }
×
46
            else
NEW
47
            {
×
48
                // Add new exported part
NEW
49
                factory.ExportedParts.Add(new ExportedItem(new Item { Name = itemName, Quantity = quantity }));
×
NEW
50
            }
×
51

52
            // Recalculate the entire plan
NEW
53
            RefreshPlanCalculations();
×
NEW
54
        }
×
55

56
        public void RemoveExportedPartFromFactory(int factoryId, string itemName)
NEW
57
        {
×
NEW
58
            if (_plan == null)
×
NEW
59
                return;
×
60

NEW
61
            var factory = _plan.Factories.FirstOrDefault(f => f.Id == factoryId);
×
NEW
62
            if (factory == null)
×
NEW
63
                return;
×
64

NEW
65
            var exportToRemove = factory.ExportedParts.FirstOrDefault(e => e.Item.Name == itemName);
×
NEW
66
            if (exportToRemove != null)
×
NEW
67
            {
×
NEW
68
                factory.ExportedParts.Remove(exportToRemove);
×
69
                
70
                // Recalculate the entire plan
NEW
71
                RefreshPlanCalculations();
×
NEW
72
            }
×
NEW
73
        }
×
74

75
        public void AddImportedPartToFactory(int factoryId, int sourceFactoryId, string sourceFactoryName, string itemName, double quantity)
NEW
76
        {
×
NEW
77
            if (_plan == null)
×
NEW
78
                return;
×
79

NEW
80
            var factory = _plan.Factories.FirstOrDefault(f => f.Id == factoryId);
×
NEW
81
            if (factory == null)
×
NEW
82
                return;
×
83

84
            // Add or update imported part
NEW
85
            var importedItem = new ImportedItem(sourceFactoryId, sourceFactoryName, new Item { Name = itemName, Quantity = quantity });
×
NEW
86
            factory.ImportedParts[sourceFactoryId] = importedItem;
×
87

88
            // Recalculate the entire plan
NEW
89
            RefreshPlanCalculations();
×
NEW
90
        }
×
91

92
        public void RefreshPlanCalculations()
NEW
93
        {
×
NEW
94
            if (_plan == null || _factoryCatalog == null)
×
NEW
95
                return;
×
96

97
            try
NEW
98
            {
×
99
                // Recalculate the plan
NEW
100
                _plan.UpdatePlanCalculations(_factoryCatalog);
×
101
                
102
                // Notify UI that plan has changed
NEW
103
                PlanChanged?.Invoke();
×
NEW
104
            }
×
NEW
105
            catch (Exception ex)
×
NEW
106
            {
×
107
                // Log error or handle it appropriately
NEW
108
                Console.WriteLine($"Error updating plan calculations: {ex.Message}");
×
NEW
109
            }
×
NEW
110
        }
×
111

112
        public void NotifyPlanChanged()
NEW
113
        {
×
NEW
114
            PlanChanged?.Invoke();
×
NEW
115
        }
×
116
    }
117
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc