public JsonResult UpdateCreate_UnidadesArmazenamento([FromBody] List <StockkeepingUnitViewModel> data) { List <StockkeepingUnitViewModel> results = DBStockkeepingUnit.ParseToViewModel(DBStockkeepingUnit.GetAll()); data.RemoveAll(x => results.Any( u => u.ProductNo == x.ProductNo && u.Description == x.Description && u.Code == x.Code && u.Inventory == x.Inventory && u.ShelfNo == x.ShelfNo && u.Blocked == x.Blocked && u.CodeWareHouse == x.CodeWareHouse && u.WareHouseValue == x.WareHouseValue && u.VendorNo == x.VendorNo && u.VendorItemNo == x.VendorItemNo && u.CodeUnitMeasure == x.CodeUnitMeasure && u.UnitCost == x.UnitCost && u.LastCostDirect == x.LastCostDirect && u.PriceSale == x.PriceSale )); data.ForEach(x => { if (!string.IsNullOrEmpty(x.ProductNo) && DBFichaProduto.GetById(x.ProductNo) != null) { UnidadeDeArmazenamento toCreate = DBStockkeepingUnit.ParseToDb(x); UnidadeDeArmazenamento toUpdate = DBStockkeepingUnit.ParseToDb(x); UnidadeDeArmazenamento toSearch = DBStockkeepingUnit.GetById(x.ProductNo); FichaProdutoViewModel product = DBFichaProduto.ParseToViewModel(DBFichaProduto.GetById(x.ProductNo)); LocationViewModel localizacao = DBLocations.ParseToViewModel(DBLocations.GetById(x.Code)); NAVVendorViewModel fornecedor = DBNAV2017Vendor.GetVendor(_config.NAVDatabaseName, _config.NAVCompanyName).Where(y => y.No_ == x.VendorNo).FirstOrDefault(); UnidadeMedidaViewModel unidadeMedida = DBUnidadeMedida.ParseToViewModel(DBUnidadeMedida.GetById(x.CodeUnitMeasure)); if (toSearch == null) { toCreate.NºProduto = x.ProductNo; toCreate.Descrição = product.Descricao; if (localizacao != null) { toCreate.CódLocalização = x.Code; } else { toCreate.CódLocalização = null; } toCreate.Inventário = x.Inventory; toCreate.NºPrateleira = x.ShelfNo; toCreate.Bloqueado = x.Blocked.HasValue ? x.Blocked.ToString().ToLower() == "sim" ? true : false : false; toCreate.ArmazémPrincipal = x.CodeWareHouse.HasValue ? x.CodeWareHouse.ToString().ToLower() == "sim" ? true : false : false; toCreate.ValorEmArmazem = x.WareHouseValue; if (fornecedor != null) { toCreate.NºFornecedor = x.VendorNo; } else { toCreate.NºFornecedor = null; } toCreate.CódProdForn = x.VendorItemNo; if (unidadeMedida != null) { toCreate.CódUnidadeMedidaProduto = x.CodeUnitMeasure; } else { toCreate.CódUnidadeMedidaProduto = null; } toCreate.CustoUnitário = x.UnitCost; toCreate.UltimoCustoDirecto = x.LastCostDirect; toCreate.PreçoDeVenda = x.PriceSale; toCreate.UtilizadorCriação = User.Identity.Name; toCreate.DataHoraCriação = DateTime.Now; DBStockkeepingUnit.Create(toCreate); } else { toUpdate.NºProduto = x.ProductNo; toUpdate.Descrição = product.Descricao; if (localizacao != null) { toUpdate.CódLocalização = x.Code; } else { toUpdate.CódLocalização = null; } toUpdate.Inventário = x.Inventory; toUpdate.NºPrateleira = x.ShelfNo; toUpdate.Bloqueado = x.Blocked.HasValue ? x.Blocked.ToString().ToLower() == "sim" ? true : false : false; toUpdate.ArmazémPrincipal = x.CodeWareHouse.HasValue ? x.CodeWareHouse.ToString().ToLower() == "sim" ? true : false : false; toUpdate.ValorEmArmazem = x.WareHouseValue; if (fornecedor != null) { toUpdate.NºFornecedor = x.VendorNo; } else { toUpdate.NºFornecedor = null; } toUpdate.CódProdForn = x.VendorItemNo; if (unidadeMedida != null) { toUpdate.CódUnidadeMedidaProduto = x.CodeUnitMeasure; } else { toUpdate.CódUnidadeMedidaProduto = null; } toUpdate.CustoUnitário = x.UnitCost; toUpdate.UltimoCustoDirecto = x.LastCostDirect; toUpdate.PreçoDeVenda = x.PriceSale; toUpdate.UtilizadorModificação = User.Identity.Name; toUpdate.DataHoraModificação = DateTime.Now; DBStockkeepingUnit.Update(toUpdate); } } }); return(Json(data)); }
public static FichaProduto ParseToDatabase(FichaProdutoViewModel x) { return(new FichaProduto() { Nº = x.No, Descrição = x.Descricao, Descrição2 = x.Descricao2, ListaDeMateriais = x.ListaDeMateriais, UnidadeMedidaBase = x.UnidadeMedidaBase, NºPrateleira = x.NoPrateleira, PreçoUnitário = x.PrecoUnitario, CustoUnitário = x.CustoUnitario, Inventário = x.Inventario, Imagem = x.Imagem, ValorEnergético = x.ValorEnergetico, ValorEnergético100g = x.ValorEnergetico100g, Proteínas = x.Proteinas, Proteínas100g = x.Proteinas100g, Glícidos = x.Glicidos, Glícidos100g = x.Glicidos100g, Lípidos = x.Lipidos, Lípidos100g = x.Lipidos100g, FibraAlimentar = x.FibraAlimentar, FibraAlimentar100g = x.FibraAlimentar100g, QuantUnidadeMedida = x.QuantUnidadeMedida, GramasPorQuantUnidMedida = x.GramasPorQuantUnidMedida, TipoRefeição = x.TipoRefeicao, DescriçãoRefeição = x.DescricaoRefeicao, Taras = x.Taras, ÁcidosGordosSaturados = x.AcidosGordosSaturados, Açucares = x.Acucares, Sal = x.Sal, Cereais = x.Cereais, Crustáceos = x.Crustaceos, Ovos = x.Ovos, Peixes = x.Peixes, Amendoins = x.Amendoins, Soja = x.Soja, Leite = x.Leite, FrutasDeCascaRija = x.FrutasDeCascaRija, Aipo = x.Aipo, Mostarda = x.Mostarda, SementesDeSésamo = x.SementesDeSesamo, DióxidoDeEnxofreESulfitos = x.DioxidoDeEnxofreESulfitos, Tremoço = x.Tremoco, Moluscos = x.Moluscos, Tipo = x.Tipo, VitaminaA = x.VitaminaA, VitaminaD = x.VitaminaD, Colesterol = x.Colesterol, Sodio = x.Sodio, Potacio = x.Potacio, Calcio = x.Calcio, Ferro = x.Ferro, Edivel = x.Edivel, Alcool = x.Alcool, DataHoraCriação = x.DataHoraCriacao, DataHoraModificação = x.DataHoraModificacao, UtilizadorCriação = x.UtilizadorCriacao, UtilizadorModificação = x.UtilizadorModificacao }); }
public JsonResult GetProductId([FromBody] string idProduct) { FichaProdutoViewModel product = DBFichaProduto.ParseToViewModel(DBFichaProduto.GetById(idProduct)); return(Json(product)); }