prvi
This commit is contained in:
61
EveryThing/Pages/Invoices/CreateItem.cshtml.cs
Normal file
61
EveryThing/Pages/Invoices/CreateItem.cshtml.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace EveryThing.Pages.Invoices
|
||||
{
|
||||
[Authorize(Roles = "Administrator,InvoicingUser,ProjecThingUser")]
|
||||
public class CreateItemModel : PageModel
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
private readonly SignInManager<IdentityApplicationUser> _loginManager;
|
||||
private readonly RoleManager<IdentityApplicationRole> _roleManager;
|
||||
|
||||
public CreateItemModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager, SignInManager<IdentityApplicationUser> loginManager, RoleManager<IdentityApplicationRole> roleManager)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
_loginManager = loginManager;
|
||||
_roleManager = roleManager;
|
||||
}
|
||||
|
||||
public IActionResult OnGet(int idInvoice)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
ViewData["IdInvoice"] = idInvoice;
|
||||
ViewData["Items"] = new SelectList(_context.CodeTableItems.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active), "IdItem", "Title");
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public Models.Invoice.InvoiceItem InvoiceItem { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnPostAsync(int idInvoice)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return Page();
|
||||
}
|
||||
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
InvoiceItem.IdInvoiceFk = idInvoice;
|
||||
|
||||
_context.InvoiceItems.Add(InvoiceItem);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return RedirectToPage("./Edit", new { id = idInvoice });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user