Esempio n. 1
0
        public IActionResult Index(HomeViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!Path.GetExtension(model.Report.FileName).Contains("csv"))
                {
                    ModelState.AddModelError(nameof(model.Report), "Please upload a file in CSV format.");
                }
                else
                {
                    model.Invoices = _reportHandler
                                     .ProcessReport(model.Report, out string message)
                                     .ToInvoices();

                    if (!string.IsNullOrWhiteSpace(message))
                    {
                        ModelState.AddModelError(nameof(model.Report), message);
                    }
                }
            }

            return(View(model));
        }