Dati azienda modifica

This commit is contained in:
Marco Audiffredi 2023-12-15 17:15:29 +01:00
parent 772888c884
commit ed7d3b177c
8 changed files with 256 additions and 76 deletions

View File

@ -294,7 +294,6 @@ namespace VirtualTask.Controllers
return RedirectToAction("Error");
}
return View(model);
}
#endregion EDIT

View File

@ -4,7 +4,9 @@ using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.DotNet.Scaffolding.Shared.CodeModifier.CodeChange;
using Microsoft.Extensions.Hosting.Internal;
using Newtonsoft.Json;
using System;
using System.Diagnostics;
using System.Reflection;
using System.Text;
using System.Web;
using VirtualTask.Models;
@ -64,27 +66,6 @@ namespace VirtualTask.Controllers
string data = response.Content.ReadAsStringAsync().Result;
modelList = JsonConvert.DeserializeObject<List<DatiAziendaTable>>(data);
//if (!string.IsNullOrEmpty(searchString))
//{
// modelList = modelList.Where(s => s.andescri.ToUpper().Contains(searchString.ToUpper())).ToList();
// ViewData["CurrentFilter"] = searchString;
//}
//else
//{
// ViewData["CurrentFilter"] = null;
//}
//if (page != null && page < 1)
//{
// page = 1;
//}
//var pageSize = 10;
//var shortLinks = modelList
// .OrderByDescending(s => s.ancodice)
// .ToPagedList(page ?? 1, pageSize);
return View(modelList);
}
else
@ -174,7 +155,109 @@ namespace VirtualTask.Controllers
#endregion CREATE
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
#region EDIT
public IActionResult Edit(string azienda,string tecnico)
{
SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok");
apiUrl = helper.GetStringValue("apiUrl");
admin = helper.GetStringValue("admin");
ViewBag.Admin = admin;
urlBase = apiUrl + "datiaziendaList";
urlBase = urlBase + "?token=" + token;
Uri baseAddress = new Uri(urlBase);
client = new HttpClient();
client.BaseAddress = baseAddress;
DatiAziendaTable dat = new DatiAziendaTable();
List<DatiAziendaTable> modelList = new List<DatiAziendaTable>();
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
if (response.IsSuccessStatusCode)
{
string data = response.Content.ReadAsStringAsync().Result;
modelList = JsonConvert.DeserializeObject<List<DatiAziendaTable>>(data);
dat = modelList.Where(t => t.azienda.Equals(azienda) && t.tecnico.Equals(tecnico)).First();
}
else
{
errMes = response.Content.ReadAsStringAsync().Result;
helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error");
}
ViewBag.AllTecnici = getTecnici();
return View(dat);
}
[HttpPost]
public IActionResult Edit(DatiAziendaTable model)
{
SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok");
tenant = helper.GetStringValue("tenant");
tenant2 = helper.GetStringValue("tenant2");
if (string.IsNullOrEmpty(token))
{
return RedirectToAction("Login2", "Login");
}
//model.azienda = tenant;
if(model.logo2!=null)
{
string pic = System.IO.Path.GetFileName(model.logo2.FileName);
string path = string.Format("{0}{1}\\{2}", _pathLoghi, tenant2, pic);
//string projectRootPath = _hostingEnvironment.ContentRootPath;
//// file is uploaded
using (Stream fileStream = new FileStream(path, FileMode.Create))
{
model.logo2.CopyToAsync(fileStream);
}
//// save the image path path to the database or you can send image
//// directly to database
//// in-case if you want to store byte[] ie. for DB
using (MemoryStream ms = new MemoryStream())
{
model.logo2.CopyTo(ms);
byte[] array = ms.GetBuffer();
model.logo = array;
}
model.logo2 = null;
}
apiUrl = helper.GetStringValue("apiUrl");
urlBase = apiUrl + "datiazienda/mod";
urlBase = urlBase + "?token=" + token;
Uri baseAddress = new Uri(urlBase);
client = new HttpClient();
client.BaseAddress = baseAddress;
string data = JsonConvert.SerializeObject(model);
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
if (response.IsSuccessStatusCode)
{
return RedirectToAction("Index");
}
else
{
errMes = response.Content.ReadAsStringAsync().Result;
helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error");
}
}
#endregion
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
SessionHelper helper = new SessionHelper(this);

View File

@ -29,5 +29,9 @@ namespace VirtualTask.Models
[Display(Name = "Testo Rapportino")]
/// <summary>testo azienda rapportino</summary>
public string? testo_buono { get; set; }
/// <summary>logo</summary>
public IFormFile? logo2 { get; set; }
}
}

View File

@ -96,11 +96,11 @@
<img alt="Modifica" src="@Url.Content("~/assets/images/icons8-modificare-64.png")" style="width:30px;height:30px;">
</a>
|
<a href="@Url.Action("Details", "Chiamate", new { id=item.chserial })" title="Dettaglio" class="links">
<a href="@Url.Action("Details", "Chiamate", new { id=item.chserial })" title="Dettaglio" class="links" >
<img alt="Dettaglio" src="@Url.Content("~/assets/images/icons8-visualizza-file-64.png")" style="width:30px;height:30px;">
</a>
|
<a href="@Url.Action("Delete", "Chiamate", new { id=item.chserial })" title="Elimina" class="links">
<a href="@Url.Action("Delete", "Chiamate", new { id=item.chserial })" title="Elimina" class="links" >
<img alt="Elimina" src="@Url.Content("~/assets/images/icons8-elimina-50.png")" style="width:30px;height:30px;">
</a>

View File

@ -1,7 +1,8 @@
@model VirtualTask.Models.DatiAzienda
@{
ViewData["Title"] = "Create";
ViewData["Title"] = "Nuovo";
Layout = "~/Views/Shared/_LayoutAreaRiservata.cshtml";
}
<h1>Create</h1>

View File

@ -0,0 +1,66 @@
@model VirtualTask.Models.DatiAziendaTable
@{
ViewData["Title"] = "Edit";
Layout = "~/Views/Shared/_LayoutAreaRiservata.cshtml";
}
<div class="agy-project-wrapper agy-project-page-wrapper">
<div class="container">
<div class="row">
<div class="row">
<div class="col-md-4">
<form asp-action="Edit" enctype="multipart/form-data">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
@Html.HiddenFor(x => x.azienda)
@Html.HiddenFor(x => x.url_logo)
@Html.HiddenFor(x => x.logo)
<div class="form-group">
<label asp-for="tecnico" class="agy-client-quote"></label>
@Html.DropDownListFor(x => x.tecnico,(IEnumerable<SelectListItem>)ViewBag.AllTecnici, new {@class = "form-control"})
<span asp-validation-for="tecnico" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ragsoc" class="agy-client-quote"></label>
<input asp-for="ragsoc" class="form-control" />
<span asp-validation-for="ragsoc" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="logo" class="agy-client-quote"></label>
@{
byte[] appo = Model.logo;
var base64 = Convert.ToBase64String(appo);
var imgSrc = String.Format("data:image/gif;base64,{0}", base64);
}
<img src="@imgSrc" height="80" />
<input type="file" asp-for="logo2" />
<span asp-validation-for="logo" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="testo_buono" class="agy-client-quote"></label>
<textarea asp-for="testo_buono" class="form-control"></textarea>
<span asp-validation-for="testo_buono" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</form>
</div>
</div>
</div>
<div>
<a asp-action="Index">Back to List</a>
</div>
</div>
</div>
<script src="~/js/tinymce/tinymce.min.js" referrerpolicy="origin"></script>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
<script>
tinymce.init({
selector: 'textarea#testo_buono'
});
</script>
}

View File

@ -1,61 +1,88 @@
@model IEnumerable<VirtualTask.Models.DatiAziendaTable>
@{
ViewData["Title"] = "Index";
ViewData["Title"] = "Dati Azienda";
Layout = "~/Views/Shared/_LayoutAreaRiservata.cshtml";
}
<h1>Index</h1>
<p>
<a asp-action="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<div class="agy-project-wrapper agy-project-page-wrapper">
<div class="container">
<div class="row">
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.tecnico)
</th>
<th>
@Html.DisplayNameFor(model => model.ragsoc)
</th>
<th>
@Html.DisplayNameFor(model => model.tecnico)
</th>
<th>
@Html.DisplayNameFor(model => model.ragsoc)
</th>
<th>
@Html.DisplayNameFor(model => model.logo)
</th>
<th>
@Html.DisplayNameFor(model => model.testo_buono)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<th>
@Html.DisplayNameFor(model => model.logo)
</th>
<th>
@Html.DisplayNameFor(model => model.testo_buono)
<td>
@Html.DisplayFor(modelItem => item.tecnico)
</td>
<td>
@Html.DisplayFor(modelItem => item.ragsoc)
</td>
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@{
var base64 = Convert.ToBase64String(item.logo);
var imgSrc = String.Format("data:image/gif;base64,{0}", base64);
}
<img src="@imgSrc" height="80" />
</td>
<td>
@Html.DisplayFor(modelItem => item.testo_buono)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</tbody>
</table>
<td>
@Html.DisplayFor(modelItem => item.tecnico)
</td>
<td>
@Html.DisplayFor(modelItem => item.ragsoc)
</td>
<td>
@{
var base64 = Convert.ToBase64String(item.logo);
var imgSrc = String.Format("data:image/gif;base64,{0}", base64);
}
<img src="@imgSrc" height="80" />
</td>
<td>
@{
string testo = string.Empty;
testo = item.testo_buono;
}
@Html.Raw(@testo)
</td>
<td>
@* @Html.ActionLink("Edit", "Edit", new { azienda=item.azienda,tecnico=item.tecnico }) |
@Html.ActionLink("Details", "Details", new { azienda=item.azienda,tecnico=item.tecnico }) |
@Html.ActionLink("Delete", "Delete", new { azienda=item.azienda,tecnico=item.tecnico })*@
<a href="@Url.Action("Edit", "DatiAzienda", new { azienda=item.azienda,tecnico=item.tecnico })" title="Modifica" class="links">
<img alt="Modifica" src="@Url.Content("~/assets/images/icons8-modificare-64.png")" style="width:30px;height:30px;">
</a>
|
<a href="@Url.Action("Details", "DatiAzienda", new { azienda=item.azienda,tecnico=item.tecnico })" title="Dettaglio" class="links" style="visibility:hidden;">
<img alt="Dettaglio" src="@Url.Content("~/assets/images/icons8-visualizza-file-64.png")" style="width:30px;height:30px;">
</a>
|
<a href="@Url.Action("Delete", "DatiAzienda", new { azienda=item.azienda,tecnico=item.tecnico })" title="Elimina" class="links" style="visibility:hidden;>
<img alt="Elimina" src="@Url.Content("~/assets/images/icons8-elimina-50.png")" style="width:30px;height:30px;">
</a>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>

View File

@ -157,8 +157,8 @@ Purchase:
<li><a asp-area="" asp-controller="Rapp_New" asp-action="Index">Buono intervento</a></li>
<li><a asp-area="" asp-controller="Chiamate" asp-action="Index">Chiamate</a></li>
<li><a asp-area="" asp-controller="Progressivi" asp-action="Index">Progressivi</a></li>
<li><a asp-area="" asp-controller="AziendaRif" asp-action="Index">Dati Azienda</a></li>
<li><a asp-area="" asp-controller="DatiAzienda" asp-action="Index">Dati Azienda2</a></li>
@* <li><a asp-area="" asp-controller="AziendaRif" asp-action="Index">Dati Azienda</a></li>*@
<li><a asp-area="" asp-controller="DatiAzienda" asp-action="Index">Dati Azienda</a></li>
<li><a asp-area="" asp-controller="CommesseVT" asp-action="Index">Commesse</a></li>
<li><a asp-area="" asp-controller="Login" asp-action="Logout">Logout</a></li>