Exemple #1
0
        public ActionResult Update(data.employee employee, long id, Boolean isAdmin, Boolean isSeller)
        {
            employee.employeeId = id;
            employee.isActive   = true;
            _employees.Update(employee);

            #region rols
            //get user
            users     _user = new users();
            data.user user  = _user.GetOneByEmployeeId(id);

            //get list of rols by id user
            users_x_rols _users_x_rols   = new users_x_rols();
            var          listUser_x_rols = _users_x_rols.GetAllByUserId(user.userId);

            data.user_x_rols user_x_rols = new data.user_x_rols();
            user_x_rols.userId = listUser_x_rols.FirstOrDefault().userId;

            //this bs is because if I use _users_x_rols generete conflict with tha primary key
            users_x_rols deleteElemento = new users_x_rols();

            if (isAdmin)
            {
                //check if exist the administrator rol
                if (listUser_x_rols.Where(x => x.rolId == 1).Count() == 0)
                {
                    user_x_rols.rolId = 1;
                    _users_x_rols.Insert(user_x_rols);
                }
            }
            else
            {
                //check if exist the administrator rol and check than exist one rol in tha user
                if (listUser_x_rols.Where(x => x.rolId == 1).Count() != 0 && (listUser_x_rols.Count() >= 2 || isSeller))
                {
                    deleteElemento.Delete(listUser_x_rols.Where(x => x.rolId == 1).FirstOrDefault());
                }
            }

            if (isSeller)
            {
                //check if exist the seller rol
                if (listUser_x_rols.Where(x => x.rolId == 2).Count() == 0)
                {
                    user_x_rols.rolId = 2;
                    _users_x_rols.Insert(user_x_rols);
                }
            }
            else
            {
                //check if exist the seller rol and check than exist one rol in tha user
                if (listUser_x_rols.Where(x => x.rolId == 2).Count() != 0 && (listUser_x_rols.Count() >= 2 || isAdmin))
                {
                    deleteElemento.Delete(listUser_x_rols.Where(x => x.rolId == 2).FirstOrDefault());
                }
            }
            #endregion rols

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public ActionResult SingIn(String userName, String password)
        {
            keys _keys = new keys();

            data.AES aes = new data.AES();

            var key = _keys.GetOneById(1);

            var employee = _employees.SingIn(aes.Encriptar(userName, key.C_Key, key.C_IV), aes.Encriptar(password, key.C_Key, key.C_IV));

            if (employee != null)
            {
                //save employee ID in Session
                HttpContext.Session.Add("employeeId", employee.employeeId);

                users_x_rols _users_x_rols = new users_x_rols();
                //find rols by user id
                byte[] rols = _users_x_rols.GetAllByUserId(employee.users.FirstOrDefault().userId).Select(x => x.rolId).ToArray();

                //save rols in Session
                HttpContext.Session.Add("rols", rols);

                return(Json(new { rols }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        public ActionResult Update(long id)
        {
            var rols = (byte[])Session["rols"];

            if (rols == null) //redirect to SinIn
            {
                return(RedirectToAction("Index", "Home"));
            }
            else if (rols.Contains <byte>(1))
            {
                var employee = _employees.GetOneById(id);

                users_x_rols _users_x_rols = new users_x_rols();
                ViewBag.rols = _users_x_rols.GetAllByUserId(employee.users.FirstOrDefault().userId);
                return(View(employee));
            }
            else//redirect to Home
            {
                return(RedirectToAction("Home", "Home"));
            }
        }