Hi,
I have a problem.
I just need to add records to the grid and then save them to the database. For this, I use part of the code sent, but it does not recognize the type of object that I have.
In addition to this, I would like to know the way in which the header data (ejs-maskedtextbox) is sent to save it in the database. I don't really understand how it works.
Hope I don't bother you with so many queries, I am new to using syncfusion.
I attach my work:
I think the problem is because I am using the urldatasource wrong
CONTROLLER:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Facturacion.Models;
using Syncfusion.EJ2.Base;
using Microsoft.EntityFrameworkCore;
using System.Collections;
using Newtonsoft.Json;
namespace Facturacion.Controllers
{
public class Factura : Controller
{
FacturacionContext ctx;
public static List order = new List();
public Factura(FacturacionContext _ctx)
{
ctx = _ctx;
}
public ActionResult Index()
{
//usando linq
//ViewBag.cabecera = ctx.VenTransaccioncabeceras.ToArray();
//ViewBag.detalle = ctx.VenTransacciondetalles.ToArray();
//ViewBag.Items = ctx.Items.ToArray();
if (order.Count == 0)
ViewBag.data = order;
var childData = ctx.VenTransacciondetalles.ToArray();
var emp = ctx.VenTransacciondetalles.ToArray();
ViewBag.foreign = emp;
return View();
}
public ActionResult Listado(){
ViewBag.listado = ctx.Listados.FromSqlRaw("select * from fn_listar_facturas(1);").ToList().ToArray();
return View();
}
public IActionResult BatchUpdate([FromBody]CRUDModel batchmodel)
{
var formData = Json(new
{
Data = JsonConvert.DeserializeObject(batchmodel.formData)
});
if (batchmodel.Added != null)
{
for (var i = 0; i < batchmodel.Added.Count(); i++)
{
order.Insert(0, batchmodel.Added[i]);
}
}
var data = order.ToList();
return Json(data);
}
public IActionResult UrlDatasource([FromBody]DataManagerRequest dm)
{
IEnumerable DataSource = order;
DataOperations operation = new DataOperations();
if (dm.Search != null && dm.Search.Count > 0)
{
DataSource = operation.PerformSearching(DataSource, dm.Search); //Search
}
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
DataSource = operation.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
int count = DataSource.Cast().Count();
if (dm.Skip != 0)
{
DataSource = operation.PerformSkip(DataSource, dm.Skip); //Paging
}
if (dm.Take != 0)
{
DataSource = operation.PerformTake(DataSource, dm.Take);
}
Console.Write(DataSource);
return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);
}
public class CRUDModel
{
public List Added { get; set; }
public List Changed { get; set; }
public List Deleted { get; set; }
public VenTransacciondetalle Value { get; set; }
public string formData { get; set; }
public int key { get; set; }
public string action { get; set; }
}
}
}
MODEL:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
#nullable disable
namespace Facturacion.Models
{
[Table("ven_transacciondetalle")]
public partial class VenTransacciondetalle
{
[Key]
[Column("det_id")]
public int DetId { get; set; }
[Column("cab_id")]
public int CabId { get; set; }
[Column("ite_id")]
public int IteId { get; set; }
[Column("det_cantidad")]
public decimal? DetCantidad { get; set; }
[Column("det_precio")]
public decimal? DetPrecio { get; set; }
[Column("det_total")]
public decimal? DetTotal { get; set; }
[Column("det_estado")]
[StringLength(1)]
public string DetEstado { get; set; }
[ForeignKey(nameof(CabId))]
[InverseProperty(nameof(VenTransaccioncabecera.VenTransacciondetalles))]
public virtual VenTransaccioncabecera Cab { get; set; }
[ForeignKey(nameof(IteId))]
[InverseProperty(nameof(Item.VenTransacciondetalles))]
public virtual Item Ite { get; set; }
}
}