void OnSelectedService(object obj) { ServiceToUpdate = obj as Service; Name = ServiceToUpdate.Name; Description = ServiceToUpdate.Description; LaborCost = ServiceToUpdate.LaborCost.ToString(); TaxPercentage = ServiceToUpdate.TaxPercentage.ToString(); Materials = ServiceToUpdate.Materials; _modifiedService = new Service(); ServiceToUpdate.Update(_modifiedService); }
public void compute_service_with_tax() { // Setup var viewModel = new ViewModel(); var servicePrice = 199.99m; var service = new Service() { Id = Guid.NewGuid().ToString(), Name = SOME_TEXT, LaborCost = servicePrice, TaxPercentage = 10 }; viewModel.Services.Add(service); // Test viewModel.AddService.Execute(service); // Verify var expected = viewModel.Total == 219.99m; Assert.IsTrue(expected); }
void Save() { decimal taxPercentage = 0.00m; var taxPercentageExists = decimal.TryParse(TaxPercentage, out taxPercentage); decimal laborCost = 0.00m; var laborCostExists = decimal.TryParse(LaborCost, out laborCost); _service = _service ?? new Service() { Id = Guid.NewGuid().ToString() }; _service.Name = Name; _service.Description = Description; _service.LaborCost = laborCost; _service.TaxPercentage = taxPercentage; _service.Materials = Materials; Publish(Messages.REQUEST_SAVE_SERVICE, _service); }
void RemoveExcessServiceMaterials(Service modifiedService, Service existingService) { var currentMaterials = modifiedService.Materials; var archivedServiceMaterials = GetServiceMaterials(existingService.Id); if (currentMaterials == null || archivedServiceMaterials == null) return; var coreMaterialIds = currentMaterials.Select(m => m.Id); var serviceMaterialMaterialIds = archivedServiceMaterials.Select(m => m.MaterialId); var materialsIdsToRemove = serviceMaterialMaterialIds.Except(coreMaterialIds); foreach (var materialId in materialsIdsToRemove) { var serviceMaterial = archivedServiceMaterials.FirstOrDefault(sm => sm.MaterialId == materialId); Publish(Messages.REQUEST_REMOVE_SERVICE_MATERIAL, serviceMaterial.Id); } }
void AddEntry(Service service) { var entry = new Entry() { Id = new Guid(service.Id), Name = service.Name, Quantity = 1, CurrentMarkupPrice = Math.Round(service.TotalCost(), 2), TaxPercentage = Math.Round(service.TaxPercentage, 3) }; Entries.Add(entry); _registry.Add(new KeyValuePair<Guid, Entry>(entry.Id, entry)); _entryDictionary.Add(service, entry); bool collectionsInSync = Entries.Count == _registry.Count && Entries.Count == _entryDictionary.Count; Debug.Assert(collectionsInSync); }
public void compute_service_with_materials() { // Setup var viewModel = new ViewModel(); var servicePrice = 199.99m; var service = new Service() { Id = Guid.NewGuid().ToString(), Name = SOME_TEXT, LaborCost = servicePrice, Materials = new ObservableCollection<Material>() { new Material() { Name = SOME_TEXT, MarkupPrice = 59.99m, Quantity = 3, UnitType = SOME_TEXT } } }; viewModel.Services.Add(service); // Test viewModel.AddService.Execute(service); // Verify var expected = viewModel.Total == 379.96m; Assert.IsTrue(expected); }
void OnViewMaterials(object obj) { Save(); IEnumerable<Material> materials = null; SubscribeFirstPublication(Messages.REQUEST_MATERIALS_RESPONSE, payload => materials = payload as IEnumerable<Material>); Publish(Messages.REQUEST_MATERIALS); if (materials != null && materials.Any()) { _service = _service ?? new Service() { Name = Name }; Publish(Messages.REQUEST_SAVE_SERVICE, _service); Publish(Messages.REQUEST_VIEW_SERVICE_MATERIALS, _service); } else { SubscribeFirstPublication(Messages.REQUEST_VIEW_NEW_MATERIAL_FORM_COMPLETED, obj2 => Publish(Messages.REQUEST_VIEW_SERVICE_MATERIALS, _service)); Publish(Messages.REQUEST_VIEW_NEW_MATERIAL); } }
public void get_material_from_service_material() { // Setup ClearSubscriptions(); var mock = new Mock(); var serviceMaterialsDatabase = mock.PrepareServiceMaterialsDependencies(); new Autonomy().Activate(); var profileId = new ProfileServer().GetProfile().Id; var material = new Material() { Name = SOME_TEXT, UserId = profileId }; Publish(Messages.REQUEST_SAVE_MATERIAL, material); var service = new Service() { Name = SOME_TEXT, UserId = profileId }; Publish(Messages.REQUEST_SAVE_SERVICE, service); var serviceMaterial = new ServiceMaterial() { MaterialId = material.Id, ServiceId = service.Id, Quantity = 1, UserId = profileId }; Publish(Messages.REQUEST_SAVE_SERVICE_MATERIAL, serviceMaterial); // Test Material materialResult = null; Subscribe(Messages.REQUEST_SERVICE_MATERIAL_RESPONSE, obj => materialResult = obj as Material); Publish(Messages.REQUEST_SERVICE_MATERIAL, material.Id); // Verify var expected = material == materialResult; Assert.IsTrue(expected); }
public bool Validate(Service service) => !string.IsNullOrWhiteSpace(service.Name) && service.LaborCost >= 0 && service.TaxPercentage >= 0;
protected override void Update(Service service) => _databaseConnection.Update(service);
protected override void Add(Service service) => _databaseConnection.Insert(service);
protected abstract void Add(Service service);
protected override void Add(Service service) => Services.Add(service);
void RemoveMaterials(Service service) { if (service.Materials != null) { foreach (var material in service.Materials) { _originalMaterials.Remove(material); } } }
protected abstract void Update(Service service);
void ProcessEntry(Service service) { Services.Add(service); AddMaterials(service); var entry = new Entry() { Id = new Guid(service.Id), Name = service.Name, Quantity = 1, CurrentMarkupPrice = Math.Round(service.TotalCost(), 2), TaxPercentage = Math.Round(service.TaxPercentage, 3) }; Entries.Add(entry); _registry.Add(new KeyValuePair<Guid, Entry>(entry.Id, entry)); _entryDictionary.Add(service, entry); SelectedEntry = entry; UpdateSummary(); }
void RemoveEntry(Service service) { Entry entry = _entryDictionary[service]; Entries.Remove(entry); _registry.Remove(_registry.First(ri => ri.Key == entry.Id)); _entryDictionary.Remove(service); }
string UpdateBlock(string serviceTemplate, Service service) { var serviceBlock = new StringBuilder(serviceTemplate); serviceBlock = serviceBlock.Replace("~SERVICE_NAME~", service.Name); serviceBlock = serviceBlock.Replace("~SERVICE_DESCRIPTION~", service.Description); serviceBlock = serviceBlock.Replace("~SERVICE_AMOUNT~", service.LaborCost.ToString()); serviceBlock = serviceBlock.Replace("~SERVICE_TAX~", string.Format("{0}%", service.TaxPercentage.ToString())); return serviceBlock.ToString(); }
public string ApplyMaterials(Service service, string materialTemplate) { var materialBlocks = new List<string>(); AddRows(service.Materials, materialBlocks, materialTemplate); var materialsBuilder = new StringBuilder(); UpdateTemplate(materialBlocks, materialsBuilder); return materialsBuilder.ToString(); }
public string ApplyMaterials(string quoteTemplate, Service service, string materialTemplate) { var materialBlocks = new List<string>(); AddRows(service.Materials, materialBlocks, materialTemplate); var materialsBuilder = new StringBuilder(); UpdateTemplate(materialBlocks, materialsBuilder); materialsBuilder.Append("</table>"); var partialTemplateUpdate = quoteTemplate.Replace(materialTemplate, materialsBuilder.ToString()); var fullTemplateUpdate = partialTemplateUpdate.Replace("~SERVICE_NAME~", "Materials"); return fullTemplateUpdate; }
void AddMaterials(Service service) { if (service.Materials != null) { foreach (var material in service.Materials) { _originalMaterials.Add(material); } } }
protected override void Update(Service service) { var existingService = Services.FirstOrDefault(s => s.Id == service.Id); service.Update(existingService); }