aggiunta gestione compagnie
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -22,6 +23,8 @@ namespace WebDoorCreator.Data.Controllers
|
||||
// Clear database context
|
||||
//Log.Info("Dispose di GWMSController");
|
||||
}
|
||||
|
||||
#region Company methods
|
||||
/// <summary>
|
||||
/// Recupera l'elenco Company (ALL)
|
||||
/// </summary>
|
||||
@@ -50,5 +53,53 @@ namespace WebDoorCreator.Data.Controllers
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adding a new company
|
||||
/// </summary>
|
||||
/// <param name="addEditRec">Record to edit or add</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> CompanyAddMod(CompanyModel addEditRec)
|
||||
{
|
||||
bool fatto = false;
|
||||
//List<ItemModel> dbResult = new List<ItemModel>();
|
||||
using (WDCDataContext localDbCtx = new WDCDataContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
var currRec = localDbCtx
|
||||
.DbSetCompany
|
||||
.Where(x => x.CompanyId == addEditRec.CompanyId)
|
||||
.FirstOrDefault();
|
||||
if (currRec != null) //if is not null edit the record found
|
||||
{
|
||||
currRec.CompanyName = addEditRec.CompanyName;
|
||||
currRec.CompanyExtCode = addEditRec.CompanyExtCode;
|
||||
currRec.Address = addEditRec.Address;
|
||||
currRec.City = addEditRec.City;
|
||||
currRec.State = addEditRec.State;
|
||||
currRec.ZipCode = addEditRec.ZipCode;
|
||||
currRec.VAT = addEditRec.VAT;
|
||||
currRec.PrivateNote = addEditRec.PrivateNote;
|
||||
currRec.CompanyToken = addEditRec.CompanyToken;
|
||||
localDbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
}
|
||||
else //if is null add the record as new in the table
|
||||
{
|
||||
localDbCtx
|
||||
.DbSetCompany
|
||||
.Add(addEditRec);
|
||||
}
|
||||
await localDbCtx.SaveChangesAsync();
|
||||
fatto = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante CompanyAddMod;{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
#endregion company methods
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ else
|
||||
</th>
|
||||
<th>Company</th>
|
||||
<th>VAT</th>
|
||||
<th class="text-end">Addess</th>
|
||||
<th class="text-center">Address</th>
|
||||
<th class="text-end">Guid</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -21,10 +21,8 @@ else
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@*@if (!item.Conf)
|
||||
{
|
||||
<button class="btn btn-primary btn-sm" @onclick="() => editRec(item)"><i class="fas fa-pen"></i></button>
|
||||
}*@
|
||||
<!-- Button trigger modal -->
|
||||
<button @onclick="()=>editRec(item)">P</button>
|
||||
</td>
|
||||
<td>
|
||||
@item.CompanyName
|
||||
|
||||
@@ -11,6 +11,9 @@ namespace WebDoorCreator.UI.Components
|
||||
[Inject]
|
||||
protected WebDoorCreatorService WDService { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<CompanyModel> E_currCompany { get; set; }
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
@@ -39,6 +42,11 @@ namespace WebDoorCreator.UI.Components
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task editRec(CompanyModel currComp)
|
||||
{
|
||||
await E_currCompany.InvokeAsync(currComp);
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,80 @@
|
||||
@page "/CompanyMan"
|
||||
@using WebDoorCreator.UI.Components
|
||||
|
||||
<div class="card">
|
||||
<h3 class="card-header">Company Management</h3>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">General Application company list</h5>
|
||||
<CompanyList></CompanyList>
|
||||
<AuthorizeView>
|
||||
<Authorized>
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between">
|
||||
<div class="fs-3">
|
||||
Company Management
|
||||
</div>
|
||||
<div>
|
||||
<!-- Button trigger modal -->
|
||||
<button type="button" class="btn btn-sm btn-success" data-bs-toggle="modal" data-bs-target="#newCompModal">
|
||||
<i class="fa-solid fa-plus"></i> Add new company
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">General Application company list</h5>
|
||||
<CompanyList E_currCompany="catchCurrComp"></CompanyList>
|
||||
</div>
|
||||
</div>
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="newCompModal" tabindex="-1" aria-labelledby="newCompModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="newCompModalLabel">Insert new company</h1>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="w-100">
|
||||
<div class="form-floating">
|
||||
<input id="companyExtCode" @bind-value="@companyExtCode" class="form-control w-100 w-100w-100 my-1" />
|
||||
<label for="companyExtCode" class="form-label">Company external code</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<textarea id="companyName" @bind="@companyName" class="form-control w-100" rows="3"></textarea>
|
||||
<label for="companyName" class="form-label">Company name</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input id="address" @bind="@address" class="form-control w-100 my-1" />
|
||||
<label for="address" class="form-label">Company address</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input id="city" type="number" @bind="@city" class="form-control w-100 my-1" />
|
||||
<label for="city" class="form-label">Company city location</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<textarea id="zipCode" @bind="zipCode" class="form-control w-100" rows="5"></textarea>
|
||||
<label for="zipCode" class="form-label">City zip code</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input id="state" type="number" @bind="@state" class="form-control w-100 my-1" />
|
||||
<label for="state" class="form-label">State</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input id="vat" type="number" @bind="@vat" class="form-control w-100 my-1" />
|
||||
<label for="vat" class="form-label">Company VAT</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input id="privateNote" @bind="@privateNote" class="form-control w-100 my-1" />
|
||||
<label for="privateNote" class="form-label">Private notes</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input id="companyToken" @bind="@companyToken" class="form-control w-100 my-1" />
|
||||
<label for="companyToken" class="form-label">Company token</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" @onclick="()=>addModNewCompany()">Close</button>
|
||||
<button type="button" class="btn btn-primary">Save changes</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -13,10 +13,141 @@ using Microsoft.AspNetCore.Components.Web.Virtualization;
|
||||
using Microsoft.JSInterop;
|
||||
using WebDoorCreator.UI;
|
||||
using WebDoorCreator.UI.Shared;
|
||||
using WebDoorCreator.Data.DbModels;
|
||||
using WebDoorCreator.UI.Data;
|
||||
|
||||
namespace WebDoorCreator.UI.Pages
|
||||
{
|
||||
public partial class CompanyMan
|
||||
{
|
||||
[Inject]
|
||||
protected WebDoorCreatorService WDService { get; set; } = null!;
|
||||
|
||||
protected CompanyModel? currCompany { get; set; } = null;
|
||||
|
||||
protected int _companyId = 0;
|
||||
protected int companyId
|
||||
{
|
||||
get => _companyId;
|
||||
set { _companyId = value; }
|
||||
}
|
||||
|
||||
protected string _companyExtCode = "";
|
||||
protected string companyExtCode
|
||||
{
|
||||
get => _companyExtCode;
|
||||
set { _companyExtCode = value; }
|
||||
}
|
||||
|
||||
protected string _companyName = "";
|
||||
protected string companyName
|
||||
{
|
||||
get => _companyName;
|
||||
set { _companyName = value; }
|
||||
}
|
||||
|
||||
protected string _address = "";
|
||||
protected string address
|
||||
{
|
||||
get => _address;
|
||||
set { _address = value; }
|
||||
}
|
||||
|
||||
protected int _zipCode = 0;
|
||||
protected int zipCode
|
||||
{
|
||||
get => _zipCode;
|
||||
set { _zipCode = value; }
|
||||
}
|
||||
|
||||
protected string _city = "";
|
||||
protected string city
|
||||
{
|
||||
get => _city;
|
||||
set { _city = value; }
|
||||
}
|
||||
|
||||
protected string _state = "";
|
||||
protected string state
|
||||
{
|
||||
get => _state;
|
||||
set { _state = value; }
|
||||
}
|
||||
protected string _vat = "";
|
||||
protected string vat
|
||||
{
|
||||
get => _vat;
|
||||
set { _vat = value; }
|
||||
}
|
||||
protected string _privateNote = "";
|
||||
protected string privateNote
|
||||
{
|
||||
get => _privateNote;
|
||||
set { _privateNote = value; }
|
||||
}
|
||||
protected string _companyToken = "";
|
||||
protected string companyToken
|
||||
{
|
||||
get => _companyToken;
|
||||
set { _companyToken = value; }
|
||||
}
|
||||
|
||||
protected async Task addModNewCompany()
|
||||
{
|
||||
Guid newCompToken = Guid.NewGuid();
|
||||
bool done = false;
|
||||
if (currCompany == null)
|
||||
{
|
||||
var newComp = new CompanyModel()
|
||||
{
|
||||
CompanyExtCode = companyExtCode,
|
||||
CompanyName = companyName,
|
||||
Address = address,
|
||||
ZipCode = zipCode,
|
||||
City = city,
|
||||
State = state,
|
||||
VAT = vat,
|
||||
PrivateNote = privateNote,
|
||||
CompanyToken = newCompToken.ToString()
|
||||
};
|
||||
|
||||
done = await WDService.CompanyAddMod(newComp);
|
||||
}
|
||||
else
|
||||
{
|
||||
var editComp = new CompanyModel()
|
||||
{
|
||||
CompanyId = companyId,
|
||||
CompanyExtCode = companyExtCode,
|
||||
CompanyName = companyName,
|
||||
Address = address,
|
||||
ZipCode = zipCode,
|
||||
City = city,
|
||||
State = state,
|
||||
VAT = vat,
|
||||
PrivateNote = privateNote,
|
||||
CompanyToken = companyToken
|
||||
};
|
||||
done = await WDService.CompanyAddMod(editComp);
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task catchCurrComp(CompanyModel? selComp)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
if(selComp != null)
|
||||
{
|
||||
currCompany = selComp;
|
||||
companyExtCode = currCompany.CompanyExtCode;
|
||||
companyName = currCompany.CompanyName;
|
||||
address = currCompany.Address;
|
||||
zipCode = currCompany.ZipCode;
|
||||
city = currCompany.City;
|
||||
state = currCompany.State;
|
||||
vat = currCompany.VAT;
|
||||
privateNote = currCompany.PrivateNote;
|
||||
companyToken = currCompany.CompanyToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user