public ActionResult NextEditItemComponent(string id)
        {
            EditIndsellCompoViewModel model = new EditIndsellCompoViewModel();

            try
            {
                var masterItems = _dbContext.tbl_IndsellCompo.Select(s => s.indSell_ItemMaster).Distinct().ToList();
                var nextItem    = "";
                for (int i = 0; i < masterItems.Count(); i++)
                {
                    if (Convert.ToString(masterItems[i]).Trim() == id.Trim())
                    {
                        if (i == masterItems.Count())
                        {
                            nextItem = id;
                        }
                        else
                        {
                            nextItem = masterItems[i + 1];
                        }

                        i = masterItems.Count() + 1;
                        break;
                    }
                }

                return(RedirectToAction("EditItemComponent", new { id = nextItem }));
            }
            catch (Exception ex)
            {
            }

            return(View(model));
        }
        public ActionResult EditItemComponent(EditIndsellCompoViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    DbfunctionUtility dbfunction = new DbfunctionUtility(_appSettings);

                    foreach (var item in model.ItemComponentList)
                    {
                        var allowed = (item.indSell_Allowed_Bool ? 1 : 0);
                        dbfunction.GetDataset("Update indSell_Compo set indSell_Allowed = " + allowed + "  where trim(indSell_ItemMaster)='" + model.indSell_ItemMaster.Trim() + "' and trim(indSell_ItemComponent)= '" + item.indSell_ItemComponent.Trim() + "' ");
                    }

                    var totalCount = model.ItemComponentList.Count();
                    var checkCount = model.ItemComponentList.Where(w => w.indSell_Allowed_Bool == true).Count();

                    if (totalCount == checkCount)
                    {
                        ViewBag.showAll = 1;
                    }
                    else
                    {
                        ViewBag.showAll = 0;
                    }

                    ViewBag.SuccessMessage = "Detail added successfully";
                    return(View(model));
                }
                else
                {
                    ViewBag.ErrorMessage = "Please enter valid values";
                }
            }
            catch (Exception ex)
            {
            }

            ViewBag.ErrorMessage = "Error occurred";

            return(View(model));
        }
        public ActionResult EditItemComponent(string id, string status = "")
        {
            EditIndsellCompoViewModel model = new EditIndsellCompoViewModel();

            try
            {
                {
                    if (status != "")
                    {
                        if (status == "Next")
                        {
                            var masterItems = _dbContext.tbl_IndsellCompo.Select(s => s.indSell_ItemMaster).Distinct().ToList();
                            var nextItem    = "";
                            for (int i = 0; i < masterItems.Count(); i++)
                            {
                                if (Convert.ToString(masterItems[i]).Trim() == id.Trim())
                                {
                                    if (i == masterItems.Count())
                                    {
                                        nextItem = id;
                                    }
                                    else
                                    {
                                        nextItem = masterItems[i + 1];
                                    }

                                    i = masterItems.Count() + 1;
                                    break;
                                }
                            }

                            id = nextItem;
                        }
                        else
                        {
                            var masterItems = _dbContext.tbl_IndsellCompo.Select(s => s.indSell_ItemMaster).Distinct().ToList();
                            var nextItem    = "";
                            for (int i = 0; i < masterItems.Count(); i++)
                            {
                                if (Convert.ToString(masterItems[i]).Trim() == id.Trim())
                                {
                                    if (i == 0)
                                    {
                                        nextItem = id;
                                    }
                                    else
                                    {
                                        nextItem = masterItems[i - 1];
                                    }


                                    i = masterItems.Count() + 1;
                                    break;
                                }
                            }

                            id = nextItem;
                        }
                    }



                    DbfunctionUtility dbfunction = new DbfunctionUtility(_appSettings);
                    DataSet           ds         = dbfunction.GetDataset(@"select indSell_Compo.*,itemmaster.Description as Item_master,itemcomponent.Description as Item_component
                                                    from indSell_Compo 
                                                    left join items as itemmaster on trim(indSell_ItemMaster) = itemmaster.Itemnum
                                                    left join items as itemcomponent on trim(indSell_Compo.indSell_ItemComponent) = itemcomponent.Itemnum where indSell_ItemMaster= " + id + "");

                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        model.ItemComponentList = (from row in ds.Tables[0].AsEnumerable()
                                                   select new IndsellCompoViewModel
                        {
                            indSell_ItemMaster = Convert.ToString(row["indSell_ItemMaster"]),
                            indSell_ItemComponent = Convert.ToString(row["indSell_ItemComponent"]),
                            indSell_Allowed_Bool = Convert.ToInt16(row["indSell_Allowed"]) == 1 ? true : false,
                            Item_master = Convert.ToString(row["Item_master"]),
                            Item_component = Convert.ToString(row["Item_component"]),
                        }).ToList();

                        var totalCount = model.ItemComponentList.Count();
                        var checkCount = model.ItemComponentList.Where(w => w.indSell_Allowed_Bool == true).Count();

                        if (totalCount == checkCount)
                        {
                            ViewBag.showAll = 1;
                        }
                        else
                        {
                            ViewBag.showAll = 0;
                        }


                        if (model.ItemComponentList.Count() > 0)
                        {
                            model.indSell_ItemMaster = model.ItemComponentList[0].indSell_ItemMaster;
                            model.Item_master        = model.ItemComponentList[0].Item_master;
                        }
                    }
                    else
                    {
                        return(RedirectToAction("ItemComponentList", "Inventory"));
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(View(model));
        }