Exemple #1
0
        public static bool Validate(string name, string laborCost, string taxPercentage)
        {
            var parsedTaxPercentage = 0.00m;
            var parsedLaborCost     = 0.00m;

            var isValidCost = decimal.TryParse(laborCost, out parsedLaborCost);

            if (!isValidCost)
            {
                return(false);
            }

            var isValidTaxPercentage = decimal.TryParse(taxPercentage, out parsedTaxPercentage);

            if (!isValidTaxPercentage)
            {
                return(false);
            }

            var validator = new ServiceValidator();

            return(validator.Validate(new Service()
            {
                Name = name, LaborCost = parsedLaborCost, TaxPercentage = parsedTaxPercentage
            }));
        }
        bool Save(object entity)
        {
            var service = entity as Service;
            var validated = new ServiceValidator().Validate(service);
            if (!validated) return false;

            Service serviceToProcess = null;

            var existingService = _services.FirstOrDefault(s => s.Id == service.Id);

            if (existingService == null)
            {
                var profile = new ProfileServer().GetProfile();

                service.UserId = profile.Id;
                service.Id = service.Id ?? Guid.NewGuid().ToString();

                _services.Add(service);
                serviceToProcess = service;
            }
            else
            {
                service.Update(existingService);
                serviceToProcess = existingService;
            }

            SaveData(serviceToProcess);
            SaveMaterials(serviceToProcess);

            return true;
        }
        public static bool Validate(string name, string laborCost, string taxPercentage)
        {
            var parsedTaxPercentage = 0.00m;
            var parsedLaborCost = 0.00m;

            var isValidCost = decimal.TryParse(laborCost, out parsedLaborCost);
            if (!isValidCost) return false;

            var isValidTaxPercentage = decimal.TryParse(taxPercentage, out parsedTaxPercentage);
            if (!isValidTaxPercentage) return false;

            var validator = new ServiceValidator();
            return validator.Validate(new Service() { Name = name, LaborCost = parsedLaborCost, TaxPercentage = parsedTaxPercentage });
        }