diff --git a/EveryThing/Pages/CodeTableItems/Index.cshtml.cs b/EveryThing/Pages/CodeTableItems/Index.cshtml.cs index 5633958..c2fa72b 100644 --- a/EveryThing/Pages/CodeTableItems/Index.cshtml.cs +++ b/EveryThing/Pages/CodeTableItems/Index.cshtml.cs @@ -60,21 +60,8 @@ namespace EveryThing.Pages.CodeTableItems .Where(x => x.IdCompanyFk == user.IdCompanyFk && EF.Functions.Like(x.Title, $"%{searchString}%") || EF.Functions.Like(x.Description, $"%{searchString}%")) - .Include(j => j.Company).Take(100).ToListAsync(); - - //Item = await _context.CodeTableItems - // .Where(x => x.IdCompanyFk == user.IdCompanyFk - // && (!search - // || EF.Functions.Like(x.Title, $"%{searchString}%") - // || (x.Description != null - // && EF.Functions.Like(x.Description, $"%{searchString}%")))) - // .Include(j => j.Company).Take(100).ToListAsync(); - - //if () - //{ - // Item = Item.Where(s => s.Title.Contains(searchString, StringComparison.InvariantCultureIgnoreCase) - // || (s.Description != null && s.Description.Contains(searchString, StringComparison.InvariantCultureIgnoreCase))).ToList(); - //} + .Include(j => j.Company) + .OrderByDescending(x => x.IdItem).Take(100).ToListAsync(); } diff --git a/EveryThing/Pages/Invoices/Edit.cshtml b/EveryThing/Pages/Invoices/Edit.cshtml index 4d52f9b..fcf9d23 100644 --- a/EveryThing/Pages/Invoices/Edit.cshtml +++ b/EveryThing/Pages/Invoices/Edit.cshtml @@ -78,6 +78,7 @@ +
diff --git a/EveryThing/Pages/Invoices/Edit.cshtml.cs b/EveryThing/Pages/Invoices/Edit.cshtml.cs index 6e1b167..520b6d4 100644 --- a/EveryThing/Pages/Invoices/Edit.cshtml.cs +++ b/EveryThing/Pages/Invoices/Edit.cshtml.cs @@ -58,36 +58,50 @@ namespace EveryThing.Pages.Invoices return NotFound(); } - Invoice = await _context.Invoices - .Include(f => f.Company).FirstOrDefaultAsync(m => m.IdInvoice == id); + var result = await LoadInvoiceData(id); - var user = _userManager.GetUserAsync(User).Result; - - if (Invoice == null) + if (!result) { return NotFound(); } + + return Page(); + } + + private async Task LoadInvoiceData(int? id) + { + Invoice = await _context.Invoices + .Include(f => f.Company).FirstOrDefaultAsync(m => m.IdInvoice == id); + + + if (Invoice == null) return false; InvoiceItems = await _context.InvoiceItems .Include(f => f.Item) .Where(m => m.IdInvoiceFk == id) .ToListAsync(); + var user = _userManager.GetUserAsync(User).Result; + ViewData["Type"] = (int)Invoice.Type; ViewData["IdPartnerFk"] = new SelectList(_context.CodeTablePartners.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active), "IdPartner", "Title"); ViewData["States"] = new SelectList(Enum.GetValues(typeof(Models.Invoice.Invoice.InvoiceState)) .Cast() .Where(x => GetAttribute(x).AllowedTypes.Split(',').Contains(((int)Invoice.Type).ToString())) - .Select(x => new { Name = GetAttribute(x).Name, Value = x.ToString()}) + .Select(x => new { Name = GetAttribute(x).Name, Value = x.ToString() }) .ToList(), "Value", "Name"); - if (!string.IsNullOrEmpty(Request.Headers["Referer"])) + if (!string.IsNullOrEmpty(Reffer)) + { + ViewData["Reffer"] = Reffer; + } + else if (!string.IsNullOrEmpty(Request.Headers["Referer"])) { ViewData["Reffer"] = Reffer = Request.Headers["Referer"].ToString(); } - return Page(); + return true; } public static TAttribute GetAttribute(Enum value) @@ -144,7 +158,9 @@ namespace EveryThing.Pages.Invoices } } - return RedirectToPage("./Edit", new { id = Invoice.IdInvoice}); + await LoadInvoiceData(Invoice.IdInvoice); + + return Page();// RedirectToPage("./Edit", new { id = Invoice.IdInvoice}); if (Reffer != null)