public async Task<ActionResult> popUpSearchVendor(string keywordId, string keywordSearch, int maxRows, int pageStart)
        {
            string sql = "WITH cte AS ( ";
            sql += "SELECT ROW_NUMBER() OVER(ORDER BY id) AS rn, ";
            sql += "[id],[vendorID],[vendorName],[npwp],[address1],[address2],[telp],[fax],[contactPerson],[ppn],[top],[createdUser],[createdDate],[modifiedUser],[modifiedDate] ";
            sql += "FROM [dbo].[Vendors] a WITH(NOLOCK) ";
            if (keywordId != string.Empty && keywordSearch != string.Empty)
            {
                sql += "WHERE " + keywordId + " LIKE  '%" + keywordSearch + "%' ";
            }
            sql += ") ";
            sql += "SELECT * FROM cte ";
            string sqlAll = sql;
            sql += "WHERE rn BETWEEN " + ((pageStart * maxRows) - (maxRows - 1)) + " AND " + (pageStart * maxRows);

            DataTable dataAll = con.executeReader(sqlAll);
            ViewBag.totalRowsVendor = dataAll.Rows.Count;
            ViewBag.currentPage = pageStart;

            DataTable popUp = con.executeReader(sql);
            List<vendor> model = new List<vendor>();
            if (popUp != null)
            {
                foreach (DataRow dr in popUp.Rows)
                {
                    DateTime? modified = dr["modifiedDate"].ToString() == string.Empty ? DateTime.Now : Convert.ToDateTime(dr["modifiedDate"].ToString());
                    var editor = new vendor()
                    {
                        id = int.Parse(dr["id"].ToString()),
                        vendorID = dr["vendorID"].ToString(),
                        vendorName = dr["vendorName"].ToString(),
                        npwp = dr["npwp"].ToString(),
                        address1 = dr["address1"].ToString(),
                        address2 = dr["address2"].ToString(),
                        telp = dr["telp"].ToString(),
                        fax = dr["fax"].ToString(),
                        contactPerson = dr["contactPerson"].ToString(),
                        ppn = bool.Parse(dr["ppn"].ToString()),
                        top = int.Parse(dr["top"].ToString()),
                        createdUser = dr["createdUser"].ToString(),
                        createdDate = DateTime.Parse(dr["createdDate"].ToString()),
                        modifiedDate = modified,
                        modifiedUser = dr["modifiedUser"].ToString()
                    };
                    model.Add(editor);
                }
                ViewBag.VendorPopUp = model.ToList();
            }

            return PartialView("_PartialPagePopUpVendorSearchSub1");
        }
Exemplo n.º 2
0
        public ActionResult Create(vendor vendor)
        {
            if (acm.cekSession() == false)
                return RedirectToAction("Logout", "Account");

            lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin;
            if (acm.cekValidation(Url.Action().ToString()) == false && lvm.isAdmin == false)
                return RedirectToAction("NotAuthorized", "Account", new { menu = Url.Action().ToString() });

            if (ModelState.IsValid)
            {
                lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin;
                vendor.createdUser = lvm.userID;
                vendor.createdDate = DateTime.Now;
                db.vendors.Add(vendor);
                db.SaveChanges();
                return RedirectToAction("Edit", "Vendor", new { id = vendor.id });
            }

            return View(vendor);
        }
Exemplo n.º 3
0
        public ActionResult Edit(vendor vendor)
        {
            if (acm.cekSession() == false)
                return RedirectToAction("Logout", "Account");

            lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin;
            if (acm.cekValidation(Url.Action().ToString()) == false && lvm.isAdmin == false)
                return RedirectToAction("NotAuthorized", "Account", new { menu = Url.Action().ToString() });

            #region preparing collect Data
            var countChkProduct = 0;
            List<string> listChkProductID = new List<string>();
            for (int i = 0; i < Request.Form.Count; i++)
            {
                if (Request.Form.AllKeys.ToList()[i].Contains("chk_"))
                {
                    countChkProduct++;
                    string[] chkVal = Request.Form.AllKeys.ToList()[i].ToString().Split('_');
                    if (!listChkProductID.Contains(chkVal[1].ToString()))
                    {
                        listChkProductID.Add(chkVal[1].ToString());
                    }
                }
            }
            #endregion

            if (ModelState.IsValid)
            {
                lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin;
                vendor.modifiedUser = lvm.userID;
                vendor.modifiedDate = DateTime.Now;
                db.Entry(vendor).State = EntityState.Modified;

                if(listChkProductID.Count() > 0)
                {
                    db.transVendorProducts.RemoveRange(db.transVendorProducts.Where(x=>x.id_vendor == vendor.id));
                    List<transVendorProduct> tvp = new List<transVendorProduct>();
                    for (int i = 0; i < listChkProductID.Count(); i++)
                    {
                        var editor = new transVendorProduct()
                        {
                            id_vendor = vendor.id,
                            productID = int.Parse(listChkProductID[i]),
                            modifiedDate = DateTime.Now,
                            modifiedUser = lvm.userID
                        };
                        db.transVendorProducts.Add(editor);
                    }
                        
                }

                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(vendor);
        }