public InvoiceFormView()
        {
            ViewModel             = new InvoiceFormViewModel();
            ViewModel.GotInvoice += invoice => { Frame.Navigate(typeof(InvoiceView), invoice); };

            this.InitializeComponent();
        }
Exemple #2
0
        public IActionResult Create(InvoiceFormViewModel invoiceModel)
        {
            Invoice invoice = new Invoice()
            {
                CustomerId = invoiceModel.SelectedCustomerId,
                Date       = DateTime.Now,
                UserId     = _userManager.GetUserId(User),
            };

            _context.Invoices.Add(invoice);

            _context.SaveChanges();

            var timeEntryEntities = invoiceModel.SelectedTimeEntries.Select(x => new TimeEntry()
            {
                Id = x, InvoiceId = invoice.Id
            });

            foreach (var timeEntryEntity in timeEntryEntities)
            {
                _context.Entry(timeEntryEntity).Property("InvoiceId").IsModified = true;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Invoices"));
        }
Exemple #3
0
        public string GetInvoiceById(int invoiceId)
        {
            var dbInvoice = invoiceService.GetInvoice(invoiceId);
            InvoiceFormViewModel viewInvoice = dbInvoice;

            return(JsonConvert.SerializeObject(viewInvoice));
        }
Exemple #4
0
        public ActionResult AddInvoiceForm(InvoiceFormViewModel invoice)
        {
            if (ModelState.IsValid)
            {
                Invoice dbInvoice = invoice;
                try
                {
                    //get company id
                    var client = clientService.GetClient(invoice.CompanyName);
                    dbInvoice.Client   = client;
                    dbInvoice.ClientId = client.ClientId;

                    invoiceService.CreateInvoice(dbInvoice);
                    invoiceService.SaveInvoice();
                    ViewBag.MainMessage = "New invoice added successfully.";
                    ViewBag.MessageType = "success";
                }
                catch (Exception e)
                {
                    ViewBag.MainMessage = "Error, new invoice was not added.";
                    ViewBag.MessageType = "danger";
                }
                return(View());
            }
            else
            {
                return(View(invoice));
            }
        }
Exemple #5
0
        public ActionResult Update(InvoiceFormViewModel invoice)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    invoiceService.UpdateInvoice(invoice);
                    invoiceService.SaveInvoice();
                    TempData["MainMessage"] = "Invoice was updated successfully.";
                    TempData["MessageType"] = "success";
                }
                catch (Exception e)
                {
                    TempData["MainMessage"] = "Error, client was not updated.";
                    TempData["MessageType"] = "danger";
                }
            }
            else
            {
                var companies = clientService.GetClients().ToList();
                ViewBag.Clients = companies;
                return(View("UpDelInvoiceForm", invoice));
            }

            return(RedirectToAction("UpDelInvoiceForm"));
        }
Exemple #6
0
        public IActionResult Create()
        {
            var viewModel = new InvoiceFormViewModel()
            {
                AvailableCustomers = _context.Customers.ToList(),

                AvailableTimeEntries = _context.TimeEntries.ToList()
                                       .Select(x => new TimeEntryFormViewModel()
                {
                    Id          = x.Id,
                    Description = x.Description,
                    TotalPrice  = x.TotalPrice
                })
            };

            return(View(viewModel));
        }
Exemple #7
0
        public ActionResult Delete(InvoiceFormViewModel invoice)
        {
            try
            {
                invoiceService.DeleteInvoice(invoice);
                invoiceService.SaveInvoice();
                //Poruke bi trebale biti izdvojene u zaseban file zbog mogucnosti lokalizacije u buducnosti
                TempData["MainMessage"] = "Invoice was deleted successfully.";
                TempData["MessageType"] = "success";
            }
            catch (Exception e)
            {
                TempData["MainMessage"] = "Error, invoice was not deleted.";
                TempData["MessageType"] = "danger";
            }

            var companies = clientService.GetClients().ToList();

            ViewBag.Clients = companies;
            return(View("UpDelInvoiceForm", invoice));
        }
Exemple #8
0
        public IActionResult Update(int id)
        {
            var invoice = _context.Invoices.Where(x => x.Id == id).Include(x => x.TimeEntries).Single();

            var invoiceModel = new InvoiceFormViewModel()
            {
                SelectedCustomerId = invoice.CustomerId,

                SelectedTimeEntries = invoice.TimeEntries.Select(x => x.Id),

                AvailableCustomers = _context.Customers.ToList(),

                AvailableTimeEntries = _context.TimeEntries.ToList()
                                       .Select(x => new TimeEntryFormViewModel()
                {
                    Id          = x.Id,
                    Description = x.Description,
                    TotalPrice  = x.TotalPrice
                })
            };

            return(View(invoiceModel));
        }
        public InvoiceForm(IViewManager viewManager, IInvoiceService invoiceService, IContragentService contragentService, IProjectService projectService)
        {
            InitializeComponent();

            InvoiceFormViewModel vm = (InvoiceFormViewModel)this.DataContext; // this creates an instance of the ViewModel

            if (vm.CloseAction == null)
            {
                vm.CloseAction = new Action(() => this.Close());
            }
            if (vm.LockInvoiceNumAction == null)
            {
                vm.LockInvoiceNumAction = new Action(() => this.NumberTextBox.IsEnabled = false);
            }
            if (vm.UnlockInvoiceNumAction == null)
            {
                vm.UnlockInvoiceNumAction = new Action(() => this.NumberTextBox.IsEnabled = true);
            }

            vm.ViewManager       = viewManager;
            vm.InvoiceService    = invoiceService;
            vm.ContragentService = contragentService;
            vm.ProjectService    = projectService;
        }