Exemple #1
0
        public ActionResult Invoice(Invoice invoice)
        {
            var userId = User.Identity.GetUserId();

            invoice.UserId = userId;


            if (!ModelState.IsValid)
            {
                var vm = PrepareInvoiceVm(invoice, userId);
                return(View("Invoice", vm));
            }

            if (invoice.Id == 0)
            {
                _invoiceRepository.Add(invoice);
            }

            else
            {
                _invoiceRepository.Update(invoice);
            }

            return(RedirectToAction("Index"));
        }
        public void ProcessPayment_Should_ReturnFailureMessage_When_PartialPaymentExistsAndAmountPaidExceedsAmountDue( )
        {
            var repo    = new InvoiceRepository( );
            var invoice = new Invoice(repo)
            {
                Amount     = 10,
                AmountPaid = 5,
                Payments   = new List <Payment>
                {
                    new Payment
                    {
                        Amount = 5
                    }
                }
            };

            repo.Add(invoice);

            var paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment = new Payment( )
            {
                Amount = 6
            };

            var result = paymentProcessor.ProcessPayment(payment);

            Assert.AreEqual("the payment is greater than the partial amount remaining", result);
        }
        public void ProcessPayment_Should_ReturnFailureMessage_When_InvoiceAlreadyFullyPaid( )
        {
            var repo = new InvoiceRepository( );

            var invoice = new Invoice(repo)
            {
                Amount     = 10,
                AmountPaid = 10,
                Payments   = new List <Payment>
                {
                    new Payment
                    {
                        Amount = 10
                    }
                }
            };

            repo.Add(invoice);

            var paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment = new Payment( );

            var result = paymentProcessor.ProcessPayment(payment);

            Assert.AreEqual("invoice was already fully paid", result);
        }
Exemple #4
0
        //po wypełnieu formularza w Invoice.cshtml wysyłamy go i kontroler musi zdefiniować akcję post
        public ActionResult Invoice(Invoice invoice)
        {
            var userId = User.Identity.GetUserId();//dla bezpieczeństwa lepiej zawsze czytać na nowo usera z bazy

            invoice.UserId = userId;

            //walidacja danych robimy przez ModeState
            if (!ModelState.IsValid)
            {
                //przygotuj model dla widoku i wyśli fakturę oraz usera

                var vm = PrepareInvoiceVm(invoice, userId);
                //zwróć view Invoice oczywiście dla GET, nie dla POST
                return(View("Invoice", vm));
            }

            if (invoice.Id == 0)
            {
                _invoiceRepository.Add(invoice);
            }
            else
            {
                _invoiceRepository.Update(invoice);
            }

            return(RedirectToAction("Index")); //zwracamy przekierowanie do listy faktur
        }
        public void ProcessPayment_Should_ReturnPartiallyPaidMessage_When_PartialPaymentExistsAndAmountPaidIsLessThanAmountDue( )
        {
            var repo    = new InvoiceRepository( );
            var invoice = new Invoice(repo)
            {
                Amount     = 10,
                AmountPaid = 5,
                Payments   = new List <Payment>
                {
                    new Payment
                    {
                        Amount = 5
                    }
                }
            };

            repo.Add(invoice);

            var paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment = new Payment( )
            {
                Amount = 1
            };

            var result = paymentProcessor.ProcessPayment(payment);

            Assert.AreEqual("another partial payment received, still not fully paid", result);
        }
        public void ProcessPayment_Should_ReturnFullyPaidMessage_When_NoPartialPaymentExistsAndAmountPaidEqualsInvoiceAmount( )
        {
            var repo    = new InvoiceRepository( );
            var invoice = new Invoice(repo)
            {
                Amount     = 10,
                AmountPaid = 0,
                Payments   = new List <Payment>( )
                {
                    new Payment( )
                    {
                        Amount = 10
                    }
                }
            };

            repo.Add(invoice);

            var paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment = new Payment( )
            {
                Amount = 10
            };

            var result = paymentProcessor.ProcessPayment(payment);

            Assert.AreEqual("invoice was already fully paid", result);
        }
Exemple #7
0
        public ActionResult Invoice(Invoice invoice)
        {
            var userId = User.Identity.GetUserId();

            invoice.UserId = userId;

            //System.IO.File.AppendAllText(@"d:\plik.txt",$"{invoice.Title} {invoice.PaymentDate} \n");

            if (!ModelState.IsValid)
            {
                var vm = PrepareInvoiceVm(invoice, userId);
                return(View("Invoice", vm));
            }

            if (invoice.Id == 0)
            {
                _invoiceRepository.Add(invoice);
            }
            else
            {
                _invoiceRepository.Update(invoice);
            }

            return(RedirectToAction("Index"));
        }
Exemple #8
0
        public void Invoice_Repository_Add_Sucessfully()
        {
            //Arrange and action
            var invoice        = _invoiceRepository.Add(_invoice);
            int idInvoiceAdded = 2;

            //Assert
            invoice.Should().NotBeNull();
            invoice.Id.Should().Be(idInvoiceAdded);
        }
        /// <summary>
        /// Save the current invoice with each line item and payment
        /// </summary>
        public void Save()
        {
            var repo = new InvoiceRepository();

            repo.Add(_invoice);
            foreach (InvoiceItem lineItem in _invoice.Items)
            {
                repo.AddLineItem(lineItem);
            }
            foreach (Payment payment in _payments)
            {
                new PaymentRepository().Add(payment);
            }
        }
Exemple #10
0
        public async Task <int> Add(AddInvoiceDto addInvoiceDto)
        {
            var invoice = new Invoice
            {
                CustomerName  = addInvoiceDto.CustomerName,
                InvoiceNumber = addInvoiceDto.InvoiceNumber,
            };

            await ThrowExceptionIfInvoiceNumberIsAlreadyExists(addInvoiceDto.InvoiceNumber);

            _repository.Add(invoice);
            await _unitOfWork.CompleteAsync();

            return(invoice.Id);
        }
Exemple #11
0
        //po wypełnieu formularza w Invoice.cshtml wysyłamy go i kontroler musi zdefiniować akcję post
        public ActionResult Invoice(Invoice invoice)
        {
            var userId = User.Identity.GetUserId();//dla bezpieczeństwa lepiej zawsze czytać na nowo usera z bazy

            invoice.UserId = userId;

            if (invoice.Id == 0)
            {
                _invoiceRepository.Add(invoice);
            }
            else
            {
                _invoiceRepository.Update(invoice);
            }

            return(RedirectToAction("Index")); //zwracamy przekierowanie do listy faktur
        }
        public async Task <IActionResult> AddClockItem(ClockItemForCreationDto clockItemForCreation)
        {
            var creator = await _userRepo.GetUser(int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value));

            var clockItem = _mapper.Map <ClockItem>(clockItemForCreation);

            clockItem.User = creator;

            _repo.Add(clockItem);

            if (await _repo.SaveAll())
            {
                var clockItemToReturn = _mapper.Map <ClockItemForReturnDto>(clockItem);
                return(CreatedAtRoute("GetClockItem", new { id = clockItem.Id }, clockItemToReturn));
            }

            throw new Exception("Creation of clock item failed on save");
        }
        public ActionResult Create(Invoice invoice, bool save)
        {
            if (!save)
            {
                invoice.State = State.Posted;
            }

            var companies = _repository.GetCompanies();

            invoice.Lines.RemoveAll(line => string.IsNullOrEmpty(line.Name));
            invoice.Customer = companies.FirstOrDefault(c => c.CompanyId == invoice.Customer.CompanyId);
            invoice.Vendor   = companies.FirstOrDefault(c => c.CompanyId == invoice.Vendor.CompanyId);
            ModelState.Clear();
            TryValidateModel(invoice);

            if (invoice.Customer == null)
            {
                ModelState.AddModelError("", @"Musisz wybrać nabywcę");
            }
            if (invoice.Vendor == null)
            {
                ModelState.AddModelError("", @"Musisz wybrać dostawcę");
            }

            if (Request.IsAjaxRequest())
            {
                if (ModelState.IsValid)
                {
                    _repository.Add(invoice);
                }
                else
                {
                    int linesAmount = invoice.Lines.Count;
                    for (int i = 0; i < 15 - linesAmount; i++)
                    {
                        invoice.Lines.Add(null);
                    }
                    return(PartialView("_CreateNewPartialView", invoice));
                }
            }

            return(PartialView("_TablePartialView", _repository.GetAll().Where(i => i.InvoiceType == invoice.InvoiceType && i.State == State.Open)));
        }
        public async Task <IActionResult> Create(Invoice invoice)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    bool result = await _repo.Add(invoice);

                    if (result)
                    {
                        return(RedirectToAction("Index"));
                    }
                    return(View("Create"));
                }
                catch
                {
                }
            }
            return(RedirectToAction("Error", "Home"));
        }
        public void ProcessPayment_Should_ReturnFailureMessage_When_NoPaymentNeeded( )
        {
            var repo = new InvoiceRepository( );

            var invoice = new Invoice(repo)
            {
                Amount     = 0,
                AmountPaid = 0,
                Payments   = null
            };

            repo.Add(invoice);

            var paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment = new Payment( );

            var result = paymentProcessor.ProcessPayment(payment);

            Assert.AreEqual("no payment needed", result);
        }
        public void ProcessPayment_Should_ReturnFailureMessage_When_NoPartialPaymentExistsAndAmountPaidExceedsInvoiceAmount( )
        {
            var repo    = new InvoiceRepository( );
            var invoice = new Invoice(repo)
            {
                Amount     = 5,
                AmountPaid = 0,
                Payments   = new List <Payment>( )
            };

            repo.Add(invoice);

            var paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment = new Payment( )
            {
                Amount = 6
            };

            var result = paymentProcessor.ProcessPayment(payment);

            Assert.AreEqual("the payment is greater than the invoice amount", result);
        }
Exemple #17
0
        public IHttpActionResult Post([FromBody] Invoice invoice)
        {
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.NotAcceptable);

            try
            {
                InvoiceRepository repository = new InvoiceRepository();
                response         = Request.CreateResponse(HttpStatusCode.OK);
                response.Content = new StringContent(JsonConvert.SerializeObject(repository.Add(invoice)));
            }
            catch (Exception ex)
            {
                Error error = new Error
                {
                    Mensaje        = ex.Message,
                    MensajeInterno = ex.InnerException != null ? ex.InnerException.Message : null
                };

                response         = Request.CreateResponse(HttpStatusCode.InternalServerError);
                response.Content = new StringContent(JsonConvert.SerializeObject(error));
            }
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            return(ResponseMessage(response));
        }
Exemple #18
0
 public int Add(Invoice invoice)
 {
     return(_invoiceRepository.Add(invoice));
 }
Exemple #19
0
 public void AddInvoice(Invoice invoice)
 {
     invoiceRepo.Add(invoice);
 }
 public bool Add(HoaDon hoaDon, ref string err)
 {
     return(invoiceRepository.Add(hoaDon, ref err));
 }
 public void Post([FromBody] Invoice invoice)
 {
     _repository.Add(invoice);
 }