private void ConvertToJmInventoryTStock(JmInventoryTStockViewModel vm, JmInventoryTStock entity)
        {
            entity.ProductId = string.IsNullOrEmpty(vm.ProductId) ? null : _JmInventoryMProductTasks.One(vm.ProductId);

            entity.StockSn         = vm.StockSn;
            entity.StockInTransId  = vm.StockInTransId;
            entity.StockInDate     = vm.StockInDate;
            entity.StockOutTransId = vm.StockOutTransId;
            entity.StockOutDate    = vm.StockOutDate;
            entity.StockStatus     = vm.StockStatus;
            entity.StockLocation   = vm.StockLocation;
            entity.StockDesc       = vm.StockDesc;
        }
        public ActionResult ViewSNContent(string EditTransDetId)
        {
            TStockInputViewModel vm = new TStockInputViewModel();

            vm.TransDetId = EditTransDetId;

            JmInventoryTTransDet det = _IJmInventoryTTransDetTasks.One(EditTransDetId);
            List <JmInventoryTStockViewModel> liststockvm = new List <JmInventoryTStockViewModel>();

            if (det != null)
            {
                IEnumerable <JmInventoryTStock> stocks = this._tasks.GetListByTransDetId(det.Id);
                string productname = det.ProductId.ProductName;
                if (stocks.Count() > 0)
                {
                    var stocksvm = from s in stocks
                                   select new JmInventoryTStockViewModel
                    {
                        StockSn       = s.StockSn,
                        ProductIdName = productname,
                        StockId       = s.Id,
                        StockOrderNo  = s.StockOrderNo
                    };
                    liststockvm = stocksvm.ToList();
                }
                else
                {
                    JmInventoryTStockViewModel stock;
                    for (int i = 0; i < det.TransDetQty; i++)
                    {
                        stock               = new JmInventoryTStockViewModel();
                        stock.StockId       = Guid.NewGuid().ToString();
                        stock.StockSn       = string.Empty;
                        stock.ProductIdName = productname;
                        stock.StockOrderNo  = (i + 1);
                        liststockvm.Add(stock);
                    }
                }
            }
            vm.Stocks = liststockvm;
            return(PartialView(vm));
        }
        public ActionResult JmInventoryTStocks_Update([DataSourceRequest] DataSourceRequest request, JmInventoryTStockViewModel vm)
        {
            if (vm != null && ModelState.IsValid)
            {
                var entity = _tasks.One(vm.StockId);
                if (entity != null)
                {
                    ConvertToJmInventoryTStock(vm, entity);

                    entity.ModifiedDate = DateTime.Now;
                    entity.ModifiedBy   = User.Identity.Name;
                    entity.DataStatus   = EnumDataStatus.Updated.ToString();

                    _tasks.Update(entity);
                }
            }

            return(Json(ModelState.ToDataSourceResult()));
        }
        public ActionResult JmInventoryTStocks_Create([DataSourceRequest] DataSourceRequest request, JmInventoryTStockViewModel vm)
        {
            if (vm != null && ModelState.IsValid)
            {
                JmInventoryTStock entity = new JmInventoryTStock();
                entity.SetAssignedIdTo(Guid.NewGuid().ToString());

                ConvertToJmInventoryTStock(vm, entity);

                entity.CreatedDate = DateTime.Now;
                entity.CreatedBy   = User.Identity.Name;
                entity.DataStatus  = EnumDataStatus.New.ToString();

                _tasks.Insert(entity);
            }

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