public IActionResult AddLineJson(InvoiceLineViewModel model) { try { if (ModelState.IsValid) { var result = InvoiceManager.AddLine(model, CurrentUser, false, true); return(Json(new { success = true, InvoiceLine = result })); } } catch (Exception e) { var innerMessage = e.InnerException == null ? "" : $": {e.InnerException.Message}"; ModelState.AddModelError("", e.Message + innerMessage); } return(Json(new { success = false, errors = ModelState.Keys.SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray() })); }
public IActionResult AddLine(InvoiceViewModel model) { try { if (ModelState.IsValid) { var result = InvoiceManager.AddLine(model.InvoiceLine, CurrentUser, false, true); TempData["Success"] = $"Dodano nową linię do faktury <b>{model.InvoiceNumber}</b>"; return(RedirectToAction("AddLine", new { model.InvoiceLine.InvoiceId })); } var line = model.InvoiceLine; model = InvoiceManager.GetInvoiceViewModelById(line.InvoiceId); model.InvoiceLine = line; return(View(model)); } catch (Exception e) { var innerMessage = e.InnerException == null ? "" : $": {e.InnerException.Message}"; TempData["Error"] = $"Wystąpił problem podczas dodwania nowej linii do faktury: {e.Message}{innerMessage}"; } return(RedirectToAction("Index")); }