示例#1
0
        public ActionResult UserDelete(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.Delete(dataContext, aclUser, user.Id);
                    if (isSuccess)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, AdminRes.SUCCESS_USER_DELETE);
                        return(RedirectToAction("Index", "Admin"));
                    }
                    ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AdminRes.ERROR_USER_DELETE);
                    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"));
            }
        }