public async Task <IActionResult> AddOrEdit(int id, [Bind("Nbr,ItemCateg,ItemCategName,ItemCategType,AddDate,UpdDate,UserName,ComputerName")] int?page, ItemCategoryModel itemCategoryModel)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new
                            { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", itemCategoryModel) }));
            }
            //Insert
            if (id == 0)
            {
                itemCategoryModel.AddDate = DateTime.Now;
                //itemCategoryModel.UpdDate = null;
                itemCategoryModel.ComputerName = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                itemCategoryModel.UserName     = User.Identity.Name;
                _context.Add(itemCategoryModel);
                await _context.SaveChangesAsync();
            }
            //Update
            else
            {
                try
                {
                    ViewBag.pageCurrent = page;

                    //update spec field EF
                    _context.ItemCategory.Attach(itemCategoryModel);

                    itemCategoryModel.UpdDate       = DateTime.Now;
                    itemCategoryModel.ItemCategName = itemCategoryModel.ItemCategName;
                    itemCategoryModel.ItemCategType = itemCategoryModel.ItemCategType;
                    itemCategoryModel.UserName      = User.Identity.Name;
                    itemCategoryModel.ComputerName  = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                    _context.Entry(itemCategoryModel).Property(x => x.UpdDate).IsModified       = true;
                    _context.Entry(itemCategoryModel).Property(x => x.ItemCategName).IsModified = true;
                    _context.Entry(itemCategoryModel).Property(x => x.ItemCategType).IsModified = true;
                    _context.Entry(itemCategoryModel).Property(x => x.UserName).IsModified      = true;
                    _context.Entry(itemCategoryModel).Property(x => x.ComputerName).IsModified  = true;



                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ItemCategoryModelExists(itemCategoryModel.Nbr))
                    {
                        return(NotFound());
                    }

                    throw;
                }
            }
            const int pageSize = 8;

            return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAll", await _context.ItemCategory.ToPagedListAsync(page ?? 1, pageSize)) }));
        }
        public async Task <ActionResult> SaveForm(string opno)
        {
            // Get data list user request
            var queryvalue = await _sptoDbContext.TempReqChange.Where(x => x.ReqOperatorID == opno& x.SendReqFlag == false).ToListAsync();


            if (queryvalue.Count != 0)
            {
                //Get Running No.
                //   string runningno;
                var progdesc  = new SqlParameter("Progdesc", "OPUPD");
                var runningNo = new SqlParameter("RunningNo", "")
                {
                    Direction = ParameterDirection.Output,
                    SqlDbType = SqlDbType.NChar
                };


                var sql            = "EXEC sprRunningNo @Progdesc,@RunningNo = @RunningNo OUTPUT SELECT @RunningNo as 'RunningNo'";
                var queryRunningNo = await _sptoDbContext.sprRunningNo.FromSql(sql, progdesc, runningNo).FirstOrDefaultAsync();

                var resultDocNo = queryRunningNo.RunningNo.Trim();
                // Initialization.

                foreach (var item in queryvalue)
                {
                    // Settings.
                    var flag  = new SqlParameter("@Flag", "Add");
                    var docNo = new SqlParameter("@DocNo", resultDocNo);
                    //var flag = new SqlParameter("@Flag", "ADD"){}
                    //var docNo = new SqlParameter("@DocNo", "TE-XXXX65");
                    var operatorId       = new SqlParameter("@OperatorID", item.OperatorID.Trim());
                    var sectionCode      = new SqlParameter("@SectionCode", item.SectionCode.Trim());
                    var sectionAttribute = new SqlParameter("@SectionAttribute", item.SectionAttribute.Trim());
                    var operatorGroup    = new SqlParameter("@OperatorGroup", item.Shift.Trim());
                    var license          = new SqlParameter("@License", item.License.Trim());
                    var active           = new SqlParameter("@Active", item.ResignStatus.Trim());
                    var reqOperatorId    = new SqlParameter("@ReqOperatorID", item.ReqOperatorID.Trim());
                    var changeOperatorId = new SqlParameter("@ChangeOperatorID", "");



                    var sqlsprOperatorReqChange = "EXEC sprOperatorReqChange @Flag, @DocNo, @OperatorID, @SectionCode, @SectionAttribute, @OperatorGroup, @License, @Active, @ReqOperatorID, @ChangeOperatorID";
                    var lst = await _sptoDbContext.Query <sprOperatorReqChange>().FromSql(sqlsprOperatorReqChange, flag,
                                                                                          docNo, operatorId, sectionCode, sectionAttribute, operatorGroup, license, active, reqOperatorId,
                                                                                          changeOperatorId).ToListAsync();
                }


                var list = await _sptoDbContext.TempReqChange.ToListAsync();

                _sptoDbContext.TempReqChange.RemoveRange(list);
                await _sptoDbContext.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
            }
            //ViewBag.DataReq = dataCollection;
            return(RedirectToAction("UserInCharge", "Management", new { opno }));
        }