public JsonResult GetUnitOfMeasure()
        {
            List <UnitMeasureProductViewModel> result = DBUnitMeasureProduct.ParseToViewModel(DBUnitMeasureProduct.GetAll());

            result.ForEach(x =>
            {
                x.ProductNoText = DBFichaProduto.GetById(x.ProductNo).Descrição;
                x.CodeText      = DBUnidadeMedida.GetById(x.Code).Description;
            });
            return(Json(result));
        }
        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 JsonResult GetProductId([FromBody] string idProduct)
        {
            FichaProdutoViewModel product = DBFichaProduto.ParseToViewModel(DBFichaProduto.GetById(idProduct));

            return(Json(product));
        }