Exemplo n.º 1
0
        public ActionResult UserEnable(int id)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
                    var userName   = User.Identity.Name;
                    var user       = AclUserContext.GetDetail(dataContext, userName);
                    if (user.AccountTypeEx != AccountTypeEnum.Admin)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }
                    var aclUser = AclUserContext.GetDetail(dataContext, id);
                    if (aclUser == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("Index", "Admin"));
                    }

                    var isSuccess = AclUserContext.Disable(dataContext, aclUser, user.Id, false);
                    if (isSuccess)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, AdminRes.SUCCESS_USER_ENABLE);
                    }
                    else
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AdminRes.ERROR_USER_ENABLE);
                    }
                    return(RedirectToAction("UserDetail", "Admin", new { id = id }));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "AdminController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }