internal byte[] GetInvoicePdf(InvoiceCreateVM model, string currentUser)
        {
            var invoice = CompileInvoice(model, currentUser);
            var newPdf  = new SEKPdfDocument(invoice);

            return(newPdf.GeneratePDF());
        }
        public IActionResult Create()
        {
            var model = new InvoiceCreateVM {
                Customers = context.GetAllCustomersAsSelectList(CurrentUser)
            };

            return(View(model));
        }
        internal Invoice CompileInvoice(InvoiceCreateVM model, string UserId)
        {
            model.InvoiceServices = JsonConvert.DeserializeObject <ServiceVM[]>(model.JsonString);
            var services = new List <Service>();

            foreach (var service in model.InvoiceServices)
            {
                services.Add(new Service(service.Label, service.Amount, service.Price));
            }
            var customer    = Customer.FirstOrDefault(o => o.Id == model.SelectedCustomer);
            var currentUser = User.FirstOrDefault(o => o.HashId == UserId);
            var invoice     = new Invoice(customer, 0.25M, services, currentUser, 000023, 30);

            return(invoice);
        }
        public FileStreamResult GetPdf(InvoiceCreateVM model)
        {
            var file = context.GetInvoicePdf(model, CurrentUser);
            // var strFile = path + Path.DirectorySeparatorChar + "faktura.pdf";
            // string mimeType = "application/pdf";
            MemoryStream output = new MemoryStream();

            output.Write(file, 0, file.Length);
            output.Position = 0;

            // HttpContext.Response.AddHeader("content-disposition", "attachment; filename=form.pdf");


            // Return the output stream
            return(File(output, "application/pdf", "Faktura.Pdf"));
        }
        public IActionResult Create(InvoiceCreateVM model, string submit)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            switch (submit)
            {
            case "Arkivera":
                return(Archive(model));

            case "Pdf":
                return(GetPdf(model));

            default:
                return(Archive(model));
            }
            //var newInvoice = context.CompileInvoice(model, CurrentUser);
            //context.PersistInvoice(newInvoice);
            //return View(model);
        }
 public IActionResult Archive(InvoiceCreateVM model)
 {
     return(View(nameof(Create), model));
 }