コード例 #1
0
        public ActionResult ProductEntry(CreateProductModel md)
        {
            if (ModelState.IsValid)
            {
                string currentUser = HttpContext.User.Identity.Name;
                int    ProductId   = md.FormSubmit.ProductId;
                if (ProductId == 0)
                {
                    bool returnresult = _accountService.CreateProduct(md.FormSubmit.SubCategoryId, md.FormSubmit.SupplierID,
                                                                      md.FormSubmit.ProductName, md.FormSubmit.ProductDesc,
                                                                      currentUser, md.FormSubmit.ProductType);
                    if (returnresult == true)
                    {
                        ModelState.Clear();
                        ViewBag.SuccessMsg = "Product created successfully";
                    }
                    else
                    {
                        ViewBag.SuccessMsg = "Error raised while creating product successfully";
                    }
                }
                else
                {
                    bool returnresult = _accountService.UpdateProduct(md.FormSubmit.ProductId, md.FormSubmit.SubCategoryId, md.FormSubmit.SupplierID,
                                                                      md.FormSubmit.ProductName, md.FormSubmit.ProductDesc,
                                                                      currentUser);
                    if (returnresult == true)
                    {
                        ModelState.Clear();
                        ViewBag.SuccessMsg = "Product information updated successfully";
                    }
                    else
                    {
                        ViewBag.Failuremessage = "Unable to update please try again later!";
                    }
                }
            }

            ViewBag.CategoryList    = _accountService.GetAllCategory(); //_accountService.SubCategory();
            ViewBag.SubCategoryList = _accountService.SubCategory();
            ViewBag.SupplierList    = _accountService.SupplierList();
            CreateProductModel     cpm            = new CreateProductModel();
            List <ProductDataList> AllProductData = _accountService.ProductDataList();
            ProductDisplay         model          = new ProductDisplay();

            model.ProductDataList = AllProductData;
            cpm.DisplayData       = model;
            model.ProductType     = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "Return", Value = "Return"
                },
                new SelectListItem {
                    Text = "Non Return", Value = "Non Return"
                },
            };
            return(View(cpm));
        }