public ActionResult Commodity_Create([DataSourceRequest] DataSourceRequest request, CommodityViewModel commodityViewModel)
        {
            if (commodityViewModel != null && ModelState.IsValid)
            {
                var commodity = CommodityViewModelBinder.BindCommodity(commodityViewModel);
                _commodityService.AddCommodity(commodity);

            }
            return Json(new[] { commodityViewModel }.ToDataSourceResult(request, ModelState));
        }
Example #2
0
        public static Commodity BindCommodity(CommodityViewModel commodityViewModel, Commodity commodity = null)
        {
            return commodity ?? new Commodity()
            {
                CommodityID = commodityViewModel.CommodityID,
                Name = commodityViewModel.Name,
                CommodityCode = commodityViewModel.CommodityCode,
                NameAM = commodityViewModel.NameAM,
                LongName = commodityViewModel.LongName,
                CommodityTypeID = commodityViewModel.CommodityTypeID,
                ParentID = commodityViewModel.CommodityTypeID

            };
        }
        public ActionResult Commodity_Update([DataSourceRequest] DataSourceRequest request, CommodityViewModel commodityViewModel)
        {
            if (commodityViewModel != null && ModelState.IsValid)
            {
                var target = _commodityService.FindById(commodityViewModel.CommodityID);
                var commodity = CommodityViewModelBinder.BindCommodity(commodityViewModel, target);
                _commodityService.EditCommodity(commodity);
            }

            return Json(new[] { commodityViewModel }.ToDataSourceResult(request, ModelState));
        }