예제 #1
0
        public ActionResult AddItem(ItemDTO item)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!item.code.Contains(" "))
                    {
                        item.created_by = 123;
                        ItemBL itemBL = new ItemBL();
                        int    count  = itemBL.CountData(new ItemSearchDTO()
                        {
                            code_key = item.code
                        });
                        if (count == 0)
                        {
                            CommonData.ReturnCode returnCode = itemBL.InsertData(item);
                            if (returnCode == CommonData.ReturnCode.Success)
                            {
                                TempData["Success"] = "Inserted Successfully!";
                            }
                            else
                            {
                                TempData["Error"] = "Insert fail";
                            }
                            Session["model.Item"] = null;
                        }
                        else
                        {
                            ModelState.AddModelError("code", "The Code already is existed! ");
                            return(RedirectToAction("Add"));
                        }

                        return(RedirectToAction("Item"));
                    }
                    else
                    {
                        ModelState.AddModelError("code", "The code must not have spaces ");
                    }
                }
                else
                {
                    CheckRegex();
                }
            }
            catch (DataException dex)
            {
                ModelState.AddModelError("", "Lỗi không xác định");
            }

            return(View("Add", LoadItemAddForm(item)));
        }
예제 #2
0
        public ActionResult Item(ItemModel model, int page = 1)
        {
            ModelState.Clear();
            if (model == null)
            {
                model       = new ItemModel();
                model.Item  = new ItemSearchDTO();
                model.Items = new StaticPagedList <ItemDTO>(new List <ItemDTO>(), 1, 20, 0);
            }
            else
            {
                if (model.Item == null)
                {
                    if (Session["model.Item"] != null && page >= 1)
                    {
                        model.Item = Session["model.Item"] as ItemSearchDTO;
                    }
                    else
                    {
                        model.Item = new ItemSearchDTO();
                    }
                }
                else
                {
                    Session["model.Item"] = model.Item;
                }
            }
            ItemBL bl = new ItemBL();

            model.Item.page_count   = bl.CountData(model.Item);
            TempData["SearchCount"] = model.Item.page_count + " row(s) has found.";
            List <ItemDTO> list;

            model.Item.page = page;
            bl.SearchData(model.Item, out list);
            model.Items = new StaticPagedList <ItemDTO>(list, model.Item.page, 20, model.Item.page_count);
            SelectList listCategory = new SelectList(categoryBL.SelectDropdownData(), "id", "name");

            ViewBag.ListCategory = listCategory;
            return(View(model));
        }
예제 #3
0
        public ActionResult AddItem(ItemDTO item)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    item.created_by = 123;
                    ItemBL itemBL = new ItemBL();
                    if (item.code.Contains(" "))
                    {
                        TempData["Error"] = "Don't input Space in ItemCode";
                        return(View("Add", LoadItemAddForm(item)));
                    }
                    int count = itemBL.CountData(new ItemDTO()
                    {
                        code = item.code
                    });
                    if (count == 0)
                    {
                        itemBL.InsertData(item);
                    }
                    else
                    {
                        TempData["Error"] = "The Code already is exister!";
                        return(View("Add", LoadItemAddForm(item)));
                    }

                    return(RedirectToAction("Item"));
                }
            }
            catch (DataException dex)
            {
                ModelState.AddModelError("", "Lỗi không xác định");
                return(RedirectToAction("SubmissionFailed", item));
            }

            return(View("Add", LoadItemAddForm(item)));
        }
예제 #4
0
        public ActionResult Item(string page, ResearchItemModel model)
        {
            ModelState.Clear();
            if (model == null)
            {
                model       = new ResearchItemModel();
                model.Item  = new ItemDTO();
                model.Items = new List <ItemDTO>();
            }
            else
            {
                if (model.Item == null)
                {
                    model.Item = new ItemDTO();
                }
                if (model.Items == null)
                {
                    model.Items = new List <ItemDTO>();
                }
            }
            if (page == null)
            {
                page = "1";
            }
            ItemBL bl = new ItemBL();

            model.page_count = bl.CountData(model.Item);
            List <ItemDTO> list;

            model.Item.page = int.Parse(page);
            bl.SearchData(model.Item, out list);
            model.Items = list;
            SelectList listCategory = new SelectList(categoryBL.SelectDropdownData(), "id", "name");

            ViewBag.ListCategory = listCategory;
            TempData["Success"]  = model.page_count + " row(s) has found.";
            return(View(model));
        }