예제 #1
0
        public ActionResult Create(/*[Bind(Include="userID,userName,email,password,isActive,lastLogin")]*/ user user)
        {
            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() });

            ViewBag.Dept = new SelectList(db.departments.ToList(), "deptID", "deptName",user.deptID);
            if (ModelState.IsValid)
            {
                lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin;
                user.createdUser = lvm.userID;
                user.createdDate = DateTime.Now;
                db.Users.Add(user);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(user);
        }
예제 #2
0
        // GET: /MenuValidation/Create
        public ActionResult Create()
        {
            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() });

            ViewBag.MenuParent = cm.ddlMenuParent(string.Empty);
            ViewBag.menuExclusive = cm.ddlMenuValidationExclusive("");
            var menuAssign = db.Menus.Where(m => m.menuIsActive == true && m.menuLink != null) // && m.menuParent != 30 && m.menuID != 30)
		     .ToList();
            ViewBag.userID = new SelectList(db.Users.Where(m => m.isActive == true && m.userID != "admin").ToList(), "userID", "userName");

            var modelMenu = new menuValidation();
            for(int i=0;i<menuAssign.Count;i++)
            {
                var editor = new menuValidation.SelectMenuAuthorize()
                {
                    Id = Convert.ToInt32(menuAssign[i].menuID.ToString()),
                    menuSelected = false,
                    Name = menuAssign[i].menuName.ToString()
                };
                modelMenu.MenuAuth.Add(editor);
            }
            ViewData["menuGeneral"] = modelMenu.MenuAuth.OrderBy(x=>x.Name).ToList();

            #region checkBoxUser
            var modelUser = new user();
            var tempUser = db.Users.Where(x => x.userID != "admin" && x.isActive == true).ToList();
            foreach (var a in tempUser)
            {
                var editor = new user.SelectActionUser()
                {
                    userId = a.userID,
                    userSelected = false,
                    userName = a.userName
                };
                modelUser.userCheckBox.Add(editor);
            }
            ViewData["userAssign"] = modelUser.userCheckBox.OrderBy(x => x.userName).ToList();
            #endregion

            //var ax = new SelectList(db.Menus.Where(m => m.menuIsActive == true && m.menuLink != null), "menuID", "menuName");
            //List<SelectListItem> categoryList = new List<SelectListItem>();
            //foreach(var a in ax.ToList())
            //{
            //    categoryList.Add(new SelectListItem { Text = a.Text, Value = a.Value });
            //}
            //model.CategoryItems = categoryList;
            
            return View();
        }
예제 #3
0
        public void loadData(menuValidation menuvalidation)
        {
            var userSaved = menuvalidation.userID.Split(',');
            var menuSaved = db.MenuValidationDetails.Where(x => x.menuValIdH == menuvalidation.menuValId).ToList();
            List<string> menuGeneralSaved = new List<string>();

            #region preparing load Data
            //if(menuvalidation)
            var countChkMenu = 0;
            var countChkUsr = 0;
            for (int i = 0; i < Request.Form.Count; i++)
            {
                if (Request.Form.AllKeys.ToList()[i].Contains("menuIDGeneral"))
                {
                    countChkMenu++;
                }
                else if (Request.Form.AllKeys.ToList()[i].Contains("rbIsGeneral"))
                {
                    menuvalidation.validationTypeIsGeneral = Convert.ToBoolean(Request.Form["rbIsGeneral"].ToString());
                }
                else if (Request.Form.AllKeys.ToList()[i].Contains("menuID"))
                {
                    //menuvalidation.menuID = Convert.ToInt32(Request.Form["menuID"].ToString());
                }
                else if (Request.Form.AllKeys.ToList()[i].Contains(".userSelected"))
                {
                    countChkUsr++;
                }
            }

            string menuExclusiveID = string.Empty;
            foreach(var ms in menuSaved)
            {
                menuGeneralSaved.Add(ms.menuID+"|"+ms.validationAccess);
                if (menuvalidation.validationTypeIsGeneral == false)
                    menuExclusiveID = ms.validationAccess;
            }
            ViewData["menuGeneralSaved"] = menuGeneralSaved;

            if (menuExclusiveID.Contains(','))
                menuExclusiveID = menuExclusiveID.Substring(0, menuExclusiveID.Length - 1);
            #endregion

            ViewBag.menuExclusive = cm.ddlMenuValidationExclusive(menuExclusiveID);
            var menuAssign = db.Menus.Where(m => m.menuIsActive == true && m.menuLink != null)// && m.menuParent != 30 && m.menuID != 30)
		     .ToList();
            ViewBag.userID = new SelectList(db.Users.Where(m => m.isActive == true && m.userID != "admin").ToList(), "userID", "userName");

            #region checkBoxMenu
            var modelMenu = new menuValidation();
            for (int i = 0; i < menuAssign.Count; i++)
            {
                var editor = new menuValidation.SelectMenuAuthorize()
                {
                    Id = Convert.ToInt32(menuAssign[i].menuID.ToString()),
                    menuSelected = false,
                    Name = menuAssign[i].menuName.ToString()
                };
                modelMenu.MenuAuth.Add(editor);
            }
            ViewData["menuGeneral"] = modelMenu.MenuAuth.OrderBy(x => x.Name).ToList();
            #endregion

            #region checkBoxUser
            var modelUser = new user();
            var tempUser = db.Users.Where(x=>x.userID != "admin").ToList();
            foreach (var a in tempUser)
            {
                bool isChecked = false;

                for(int i=0; i<userSaved.Length; i++)
                {
                    if(userSaved[i].ToString() == a.userID)
                    {
                        isChecked = true;
                        break;
                    }
                }

                var editor = new user.SelectActionUser()
                {
                    userId = a.userID,
                    userSelected = isChecked,
                    userName = a.userName
                };
                modelUser.userCheckBox.Add(editor);
            }
            ViewData["userAssign"] = modelUser.userCheckBox.OrderBy(x => x.userName).ToList();
            #endregion
        }
예제 #4
0
        public ActionResult Edit(menuValidation menuvalidations)
        {
            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() });

            menuValidation menuvalidation = db.MenuValidations.Find(menuvalidations.menuValId/*, menuvalidations.menuID, menuvalidations.userID*/);

            ViewBag.menuExclusive = cm.ddlMenuValidationExclusive("");
            var menuAssign = db.Menus.Where(m => m.menuIsActive == true && m.menuLink != null).ToList();
            ViewBag.userID = new SelectList(db.Users.Where(m => m.isActive == true && m.userID != "admin").ToList(), "userID", "userName");

            #region preparing collect Data
            var countChkMenu = 0;
            var countChkUsr = 0;
            int cbMenu = 0;
            string valAccess = string.Empty;
            for (int i = 0; i < Request.Form.Count; i++)
            {
                if (Request.Form.AllKeys.ToList()[i].Contains("menuIDGeneral"))
                {
                    countChkMenu++;
                }
                else if (Request.Form.AllKeys.ToList()[i].Contains("rbIsGeneral"))
                {
                    menuvalidation.validationTypeIsGeneral = Convert.ToBoolean(Request.Form["rbIsGeneral"].ToString());
                }
                else if (Request.Form.AllKeys.ToList()[i].ToString() == "menu")
                {
                    //menuvalidation.menuID = Convert.ToInt32(Request.Form["menuID"].ToString());
                    valAccess = Request.Form["menu"].ToString();
                }
                else if (Request.Form.AllKeys.ToList()[i].Contains(".userSelected"))
                {
                    countChkUsr++;
                }
            }
            #endregion

            #region checkBoxMenu
            var modelMenu = new menuValidation();
            for (int i = 0; i < menuAssign.Count; i++)
            {
                var editor = new menuValidation.SelectMenuAuthorize()
                {
                    Id = Convert.ToInt32(menuAssign[i].menuID.ToString()),
                    menuSelected = false,
                    Name = menuAssign[i].menuName.ToString()
                };
                modelMenu.MenuAuth.Add(editor);
            }
            ViewData["menuGeneral"] = modelMenu.MenuAuth.ToList();
            #endregion

            #region checkBoxUser
            var modelUser = new user();
            var tempUser = db.Users.Where(x => x.userID != "admin" && x.isActive == true).ToList();
            foreach (var a in tempUser)
            {
                var editor = new user.SelectActionUser()
                {
                    userId = a.userID,
                    userSelected = false,
                    userName = a.userName
                };
                modelUser.userCheckBox.Add(editor);
            }
            ViewData["userAssign"] = modelUser.userCheckBox.ToList();
            #endregion

            if (ModelState.IsValid)
            {
                lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin;
                try
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        string userAssigned = string.Empty;
                        for (int i = 0; i < countChkUsr; i++)
                        {
                            var checkboxValue = Request.Form["[" + i + "].userSelected"].Split(',');

                            if (checkboxValue[0].ToString().ToLower() != "false")
                            {
                                userAssigned += checkboxValue[0].ToString() + ",";
                            }
                        }

                        menuvalidation.validationName = menuvalidations.validationName;
                        menuvalidation.userID = userAssigned.Substring(0, userAssigned.Length - 1);
                        menuvalidation.modifiedDate = DateTime.Now;
                        menuvalidation.modifiedUser = lvm.userID;
                        db.Entry(menuvalidation).State = EntityState.Modified;
                        db.SaveChanges();

                        db.MenuValidationDetails.RemoveRange(db.MenuValidationDetails.Where(x => x.menuValIdH == menuvalidation.menuValId));

                        if (menuvalidation.validationTypeIsGeneral == true)
                            for (int m = 0; m < countChkMenu; m++)
                            {
                                cbMenu = Convert.ToInt32(Request.Form["menuIDGeneral" + m].ToString());
                                valAccess = string.Empty;

                                var cbInsert = Request.Form["insert_" + m].Split(',');
                                valAccess += cbInsert[0].ToString().ToLower() != "false" ? "i," : "";
                                var cbUpdate = Request.Form["update_" + m].Split(',');
                                valAccess += cbUpdate[0].ToString().ToLower() != "false" ? "u," : "";
                                var cbDelete = Request.Form["delete_" + m].Split(',');
                                valAccess += cbDelete[0].ToString().ToLower() != "false" ? "d," : "";
                                var cbView = Request.Form["view_" + m].Split(',');
                                valAccess += cbView[0].ToString().ToLower() != "false" ? "v," : "";

                                if (valAccess != string.Empty)
                                {
                                    db.MenuValidationDetails.Add(new menuValidation.menuValidationDetail()
                                    {
                                        menuValIdH = menuvalidation.menuValId,
                                        menuID = cbMenu,
                                        validationAccess = valAccess.Substring(0, valAccess.Length - 1)
                                    });
                                }
                            }
                        else
                            db.MenuValidationDetails.Add(new menuValidation.menuValidationDetail()
                            {
                                menuValIdH = menuvalidation.menuValId,
                                menuID = cbMenu,
                                validationAccess = valAccess
                            });

                        db.SaveChanges();
                        ts.Complete();
                        return RedirectToAction("Index");
                    }
                }
                catch (Exception exc)
                {
                    string a = exc.Message;
                }
            }
            return View(menuvalidation);
        }
예제 #5
0
        public ActionResult Edit(/*[Bind(Include="userID,userName,email,password,isActive,lastLogin")] */user user)
        {
            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)
            {
                for (int i = 0; i < Request.Form.Count; i++)
                {
                    if (Request.Form.AllKeys.ToList()[i].Contains("passwordNew"))
                    {
                        if (Request.Form["passwordNew"].ToString() != string.Empty)
                        {
                            string encPassword = ccm.Encrypt(Request.Form["passwordNew"].ToString().Trim());
                            user.password = encPassword;
                            break;
                        }
                    }
                }
                
                lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin;
                user.modifiedUser = lvm.userID;
                user.modifiedDate = DateTime.Now;
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.Dept = new SelectList(db.departments.ToList(), "deptID", "deptName", user.deptID);
            return View(user);
        }
예제 #6
0
		public ActionResult Create(employee employee)
		{
			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 collect userid
			string userID = string.Empty;
			string typeCreated = string.Empty;
			string statusNikah = string.Empty;
			string agama = string.Empty;
			string kewarganegaraan = string.Empty;
			bool existingBank = false;
			string namaBank = string.Empty;
			for (int i = 0; i < Request.Form.Count; i++)
			{
				if (Request.Form.AllKeys.ToList()[i].Contains("userID"))
				{
					userID = Request.Form["userID"].ToString();
				}
				else if (Request.Form.AllKeys.ToList()[i].Contains("typeCreate"))
				{
					typeCreated += Request.Form["typeCreate"].ToString().Substring(0, 1) + ",";
				}
				else if (Request.Form.AllKeys.ToList()[i].Contains("typeCreateUserId"))
				{
					typeCreated += Request.Form["typeCreateUserId"].ToString().Substring(0, 1);
				}
				else if (Request.Form.AllKeys.ToList()[i].Contains("existingBank"))
				{
					string[] chkExistingBank = Request.Form["existingBank"].ToString().Split(',');
					existingBank = bool.Parse(chkExistingBank[0]);
				}
				else if (Request.Form.AllKeys.ToList()[i].Contains("ddlBank"))
				{
					namaBank = Request.Form["ddlBank"].ToString();
				}
				else if (Request.Form.AllKeys.ToList()[i].Contains("userID"))
				{
					userID = Request.Form["userID"].ToString();
				}
				else if (Request.Form.AllKeys.ToList()[i].Contains("userID"))
				{
					userID = Request.Form["userID"].ToString();
				}
				else if (Request.Form.AllKeys.ToList()[i].Contains("userID"))
				{
					userID = Request.Form["userID"].ToString();
				}
			}
			#endregion

			ViewBag.NIK = employee.employeeNIK;
			ViewBag.typeCreate = typeCreated;
			ViewBag.userID = userID;
			ViewBag.ListBankExistingOnEmployee = ccm.ddlBankEmployee(namaBank);
			ViewBag.existingBank = existingBank;
			//ViewBag.posDate = DateTime.Now;
			//ViewBag.resDate = DateTime.Now;
			//ViewBag.DeptList = ccm.ddlDepartment(string.Empty);
			//ViewBag.DivList = ccm.ddlDivisi(string.Empty);
			//ViewBag.LevelList = ccm.ddlLevel(string.Empty);
			//ViewBag.StatusList = ccm.ddlStatusEmployee(string.Empty);

			ViewBag.Gender = employee.jenisKelamin;
			ViewBag.statusNikah = ccm.statusNikah(employee.statusNikah);
			ViewBag.agama = ccm.agama(employee.agama);
			ViewBag.kewarganegaraan = ccm.kewarganegaraan(employee.kewarganegaraan);
			if (ModelState.IsValid)
			{
				List<employee.employeePosition> empPos = Session["detailPositionSession"] as List<employee.employeePosition>;
				try
				{
					using (TransactionScope ts = new TransactionScope())
					{
						string prefix = DateTime.Now.Year.ToString().Substring(2) + DateTime.Now.Month.ToString("d2");
						var nikCreated = db.employees.Where(x => x.employeeNIK.Contains(prefix)).OrderByDescending(x => x.employeeID).Select(x => x.employeeNIK).ToList();
						if (nikCreated.Count == 0)
						{
							employee.employeeNIK = prefix + "001";
						}
						else
						{
							employee.employeeNIK = prefix + (Convert.ToInt32(nikCreated[0].Substring((nikCreated[0].Length - 3))) + 1).ToString().PadLeft(3, '0');
						}

						lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin;
						employee.createdUser = lvm.userID;
						employee.createdDate = DateTime.Now;
						employee.bankName = existingBank == true ? namaBank : employee.bankName;
						db.employees.Add(employee);

						#region create user
						string encPassword = ccm.Encrypt(userID.Trim());

						user usr = new user();
						usr.userID = userID;
						usr.userName = employee.employeeName;
						usr.email = employee.email;
						usr.isActive = true;
						usr.password = encPassword;
						usr.deptID = 0;
						usr.createdDate = employee.createdDate;
						usr.createdUser = employee.createdUser;
						usr.employeeNIK = employee.employeeNIK;
						db.Users.Add(usr);
						#endregion

						db.SaveChanges();
						ts.Complete();
					}
					//return RedirectToAction("Index");

					var employeeID = db.employees
							  .Join(db.Users.Where(x => x.employeeNIK == employee.employeeNIK), a => a.employeeNIK, b => b.employeeNIK, (a, b) => new { a, b })
							  .Select(x => new { x.a.employeeID }).ToList();
					return RedirectToAction("Edit", "Employee", new { id = employeeID[0].employeeID });
				}
				catch (Exception exc)
				{
					string a = exc.Message;
				}
			}

			return View(employee);
		}