Ejemplo n.º 1
0
        public ActionResult InvoicePosition(InvoicePossition invoicePosition)
        {
            var userId = User.Identity.GetUserId();

            // zweryfikujemy, czy uzytkownik próbuje zaktualizować swoją fakturę
            // dodajemy lub aktualizujemy pozycję faktury
            // wyliczymy wartość pozycji
            // wyliczymy i zaktualizujemy wrtość faktury


            if (!ModelState.IsValid)
            {
                var vm = PrepareInvoicePositionVm(invoicePosition);
                return(View("InvoicePosition", vm));
            }

            var product = _productRepository.GetProduct(invoicePosition.ProductId);

            invoicePosition.Value = product.Value * invoicePosition.Quantity;

            if (invoicePosition.Id == 0)
            {
                _invoiceRepository.AddPosition(invoicePosition, userId);
            }
            else
            {
                _invoiceRepository.UpdatePosition(invoicePosition, userId);
            }

            _invoiceRepository.UpdateInvoiceValue(invoicePosition.InvoiceId, userId);

            return(RedirectToAction("Invoice", new { id = invoicePosition.InvoiceId }));
        }
Ejemplo n.º 2
0
        public ActionResult InvoicePosition(InvoicePosition invoicePosition)
        {
            var userId  = User.Identity.GetUserId();//dla bezpieczeństwa lepiej zawsze czytać na nowo usera z bazy
            var product = _productRepository.GetProduct(invoicePosition.ProductId);

            invoicePosition.Product = product;
            invoicePosition.Value   = invoicePosition.Quantity * product.Value;

            //walidacja danych robimy przez ModeState
            //wymagania co do walidacji sa opisane w modelu np Required
            if (!ModelState.IsValid)
            {
                //przygotuj model dla widoku i wyśli poz fakturę oraz usera

                var vm = PrepareInvoicePositionVm(invoicePosition);
                //zwróć view invoicePosition oczywiście dla GET, nie dla POST
                return(View("InvoicePosition", vm));
            }

            if (invoicePosition.Id == 0)
            {
                _invoiceRepository.AddPosition(invoicePosition, userId);
            }
            else
            {
                _invoiceRepository.UpdatePosition(invoicePosition, userId);
            }

            _invoiceRepository.UpdateInvoiceValue(invoicePosition.InvoiceId, userId);

            return(RedirectToAction("Invoice",
                                    new { id = invoicePosition.InvoiceId })); //zwracamy przekierowanie
        }
Ejemplo n.º 3
0
        public ActionResult InvoicePosition(InvoicePosition invoicePosition)
        {
            var userId = User.Identity.GetUserId();

            var product = _productRepository
                          .GetProduct(invoicePosition.ProductId);

            if (!ModelState.IsValid)
            {
                var vm = PrepareInvoicePositionVm(invoicePosition);
                return(View("IvoicePosition", vm));
            }

            invoicePosition.Value = invoicePosition.Quantity * product.Value;

            if (invoicePosition.Id == 0)
            {
                _invoiceRepository.AddPosition(invoicePosition, userId);
            }

            else
            {
                _invoiceRepository.UpdatePosition(invoicePosition, userId);
            }

            _invoiceRepository.UpdateInvoiceValue(invoicePosition.InvoiceId, userId);

            return(RedirectToAction("Invoice",
                                    new { id = invoicePosition.InvoiceId }));
        }
Ejemplo n.º 4
0
        public ActionResult InvoicePosition(InvoicePosition invoicePosition)
        {
            var userId  = User.Identity.GetUserId();//dla bezpieczeństwa lepiej zawsze czytać na nowo usera z bazy
            var product = _productRepository.GetProduct(invoicePosition.ProductId);

            invoicePosition.Value = invoicePosition.Quantity * product.Value;

            if (invoicePosition.Id == 0)
            {
                _invoiceRepository.AddPosition(invoicePosition, userId);
            }
            else
            {
                _invoiceRepository.UpdatePosition(invoicePosition, userId);
            }

            _invoiceRepository.UpdateInvoiceValue(invoicePosition.InvoiceId, userId);

            return(RedirectToAction("Invoice",
                                    new { id = invoicePosition.InvoiceId })); //zwracamy przekierowanie
        }