Example #1
0
        public dynamic Edit([FromRoute] int id, [FromBody] Form form)
        {
            Invoice invoice = Mapper.Map <Invoice>(form);

            if (!_context.Invoices.Any(x => x.Id == invoice.Id))
            {
                return(new BadRequestObjectResult(new { messages = new List <string> {
                                                            finance.Resources.Messages.InvoiceNotExisting
                                                        } }));
            }

            InvoiceValidator validator = new InvoiceValidator(_context);
            ValidationResult result    = validator.Validate(invoice);

            if (!result.IsValid)
            {
                Hashtable errors = FormatErrors(result);
                return(new OkObjectResult(new { Errors = errors }));
            }

            _context.Invoices.Update(invoice);
            _context.SaveChanges();

            return(new OkObjectResult(new { data = Mapper.Map <Form>(invoice) }));
        }
Example #2
0
        public dynamic Create([FromBody] Form form)
        {
            Invoice invoice = Mapper.Map <Invoice>(form);

            InvoiceValidator validator = new InvoiceValidator(_context);
            ValidationResult result    = validator.Validate(invoice);

            if (!result.IsValid)
            {
                Hashtable errors = FormatErrors(result);
                return(new BadRequestObjectResult(new { Errors = errors }));
            }

            dynamic billetResponseObject = GetBilletUrl(form);

            if (billetResponseObject.success != true)
            {
                return(new BadRequestObjectResult(new { billetResponseObject.messages }));
            }

            invoice.Billet = billetResponseObject.url;
            _context.Invoices.Add(invoice);
            _context.SaveChanges();

            return(new OkObjectResult(new { data = Mapper.Map <Form>(invoice) }));
        }
        public void InvoiceValidatorTest()
        {
            var invoice = CreateInvoice();

            IValidator validator = new InvoiceValidator();
            var        result    = validator.Validate(invoice);

            Assert.IsTrue(result.IsValid);
        }
        public void InvoicenValidatorNoValidTest()
        {
            var invoice = CreateInvoice();

            invoice.SerieDocumento = "G001";

            IValidator validator = new InvoiceValidator();
            var        result    = validator.Validate(invoice);

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
        }
Example #5
0
        public static Invoice ByCustomer(string customer, string invoiceNumber)
        {
            Enforce
            .Argument(() => customer)
            .Argument(() => invoiceNumber);

            var invoice = new Invoice {
                Customer = customer, Number = invoiceNumber
            };

            InvoiceValidator.Validate(invoice);

            return(invoice);
        }
        public Task <List <InvoiceError> > Handle(ValidateJobInvoiceCommand request, CancellationToken cancellationToken)
        {
            var result = new List <InvoiceError>();

            var invoiceValidator = new InvoiceValidator(request.Job, _ctx);

            if (invoiceValidator.MaterialValidators.Any())
            {
                invoiceValidator.RunMaterialValidators();
            }

            result.AddRange(invoiceValidator.InvoiceErrors);

            return(Task.FromResult <List <InvoiceError> >(result));
        }
        static void validate(Invoice invoice)
        {
            InvoiceValidator Validator = new InvoiceValidator();
            Set violations             = Validator.validate(invoice);

            if (violations.size() > 0)
            {
                System.Console.WriteLine("Invoice has (" + violations.size() + ") violations.");
                foreach (ConstraintViolation violation in violations.toArray())
                {
                    System.Console.Write(violation.getMessage() + " @ ");
                    System.Console.Write(violation.getPropertyPath() + "\n");
                }
            }
            else
            {
                System.Console.WriteLine("No Violations in invoice found ");
            }
        }
        public IActionResult Save(int vehicleId, InvoiceFormModel formModel)
        {
            try
            {
                var validator = new InvoiceValidator();
                var results   = validator.Validate(formModel);

                if (results.Errors.Any())
                {
                    foreach (var error in results.Errors)
                    {
                        ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                    }
                }

                if (!ModelState.IsValid)
                {
                    return(View("InvoiceForm", formModel));
                }

                var invoice = (formModel.InvoiceId == AppStrings.NotSet) ?
                              _mapper.Map <Invoice>(formModel) :
                              _mapper.Map <InvoiceFormModel, Invoice>(formModel, _invoiceService.GetInvoice(formModel.InvoiceId));

                _invoiceService.SaveInvoice(invoice);

                TempData["SuccessMessage"] = AppStrings.InvoiceSavedSuccessMsg;
                return(RedirectToAction("Details", "Vehicle", new { id = vehicleId }));
            }
            catch (VehicleNotFoundException ex)
            {
                _logger.LogWarning(ex.Message);
                TempData["ErrorMessage"] = AppStrings.GenericErrorMsg;
                return(RedirectToAction("Index", "Vehicle"));
            }
            catch (Exception ex)
            {
                _logger.LogWarning($"Error occurred while attempting to save repair. {ex.Message}");
                TempData["ErrorMessage"] = AppStrings.GenericErrorMsg;
                return(RedirectToAction("Index", "Vehicle"));
            }
        }
Example #9
0
        //  Verify that invoice object has valid information before committing to the database.
        private bool ValidateInvoiceInformation()
        {
            // Validate my data and save in the results variable
            InvoiceValidator invoiceValidator = new InvoiceValidator();
            var results = invoiceValidator.Validate(this.invoice);

            // Check if the validator found any validation errors.
            if (results.IsValid == false)
            {
                foreach (ValidationFailure failure in results.Errors)
                {
                    MessageBox.Show($"{ failure.ErrorMessage }", "Invoice Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #10
0
        public CheckResult DeleteInvoice(InvoiceModel model)
        {
            try
            {
                using (var db = DB.GetContext())
                {
                    var check = InvoiceValidator.ValidateDelete(db, model);
                    if (check.Failed)
                    {
                        return(check);
                    }

                    InvoiceRepository.DeleteInvoice(db, model);
                    db.SaveChanges();
                    return(check);
                }
            }
            catch (Exception ex)
            {
                return(new CheckResult(ex));
            }
        }
Example #11
0
        public async Task <InvoiceInsertResponse> InsertOneAsync(AddInvoiceModel invoiceModel)
        {
            var invoiceValidator = new InvoiceValidator(_currencyRepository);
            var response         = await invoiceValidator.ValidateInvoiceCurrencies(invoiceModel);

            if (response.ValidationResult.Status == ValidationStatus.Error)
            {
                return(await Task.FromResult(response));
            }

            var invoice = _mapper.Map <Invoice>(invoiceModel);

            invoice.Number = await GenerateInvoiceNumberAsync();

            invoice.TotalAmount = await _calculator.CalculateTotalAmount(invoice.Items);

            await _invoiceRepository.InsertOneAsync(invoice);

            response.InvoiceNumber = invoice.Number;

            return(await Task.FromResult(response));
        }
Example #12
0
        public CheckResult SaveInvoice(InvoiceModel model)
        {
            try
            {
                using (var db = DB.GetContext())
                {
                    var check = InvoiceValidator.ValidateSave(db, model);
                    if (check.Failed)
                    {
                        return(check);
                    }

                    KeyBinder key = new KeyBinder();
                    InvoiceRepository.SaveInvoice(db, key, model);
                    db.SaveChanges();
                    key.BindKeys();
                    return(check);
                }
            }
            catch (Exception ex)
            {
                return(new CheckResult(ex));
            }
        }
		static void validate(Invoice invoice){
			
			InvoiceValidator Validator = new InvoiceValidator();
			Set violations = Validator.validate(invoice);  		

			if (violations.size() > 0) {
				System.Console.WriteLine("Invoice has (" + violations.size()  + ") violations.");
				foreach (ConstraintViolation violation in violations.toArray()){
					System.Console.Write (violation.getMessage() + " @ ");
					System.Console.Write (violation.getPropertyPath() + "\n");
				}
			} else {
				System.Console.WriteLine ("No Violations in invoice found ");
			}
		}