Ejemplo n.º 1
0
        public ActionResult Add(string key)
        {
            var model = new MenuGroup();

            try
            {
                if (key != Keyapi)
                {
                    return(Json(0, JsonRequestBehavior.AllowGet));
                }
                UpdateModel(model);
                model.AgencyID = Agencyid();
                model.Name     = HttpUtility.UrlDecode(model.Name);
                model.Des      = HttpUtility.UrlDecode(model.Des);
                _da.Add(model);
                _da.Save();
                return(Json(model.Id, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(0, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Actions()
        {
            var msg   = new JsonMessage();
            var model = new MenuGroup();
            List <MenuGroup> ltsMenuGroups;
            StringBuilder    stbMessage;

            switch (DoAction)
            {
            case ActionType.Add:
                try
                {
                    UpdateModel(model);
                    model.CreatedDate = DateTime.Now;
                    model.AgencyID    = Utility.AgencyId;
                    _menuGroupsDa.Add(model);
                    _menuGroupsDa.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = model.Id.ToString(),
                        Message = string.Format("Đã thêm mới vị trí : <b>{0}</b>", Server.HtmlEncode(model.Name))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }
                break;

            case ActionType.Edit:
                try
                {
                    model = _menuGroupsDa.GetById(ArrId.FirstOrDefault());
                    UpdateModel(model);
                    _menuGroupsDa.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = model.Id.ToString(),
                        Message = string.Format("Đã cập nhật : <b>{0}</b>", Server.HtmlEncode(model.Name))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }
                break;

            case ActionType.Delete:
                ltsMenuGroups = _menuGroupsDa.GetListByArrId(ArrId);
                stbMessage    = new StringBuilder();
                foreach (var item in ltsMenuGroups)
                {
                    _menuGroupsDa.Delete(item);
                    stbMessage.AppendFormat("Đã xóa <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                msg.ID = string.Join(",", ArrId);
                _menuGroupsDa.Save();
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Show:
                ltsMenuGroups = _menuGroupsDa.GetListByArrId(ArrId).Where(o => o.IsShow == false).ToList();
                stbMessage    = new StringBuilder();
                foreach (var item in ltsMenuGroups)
                {
                    item.IsShow = true;
                    stbMessage.AppendFormat("Đã hiển thị <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                _menuGroupsDa.Save();
                msg.ID      = string.Join(",", ltsMenuGroups.Select(o => o.Id));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Hide:
                ltsMenuGroups = _menuGroupsDa.GetListByArrId(ArrId).Where(o => o.IsShow != null && o.IsShow == true).ToList();
                stbMessage    = new StringBuilder();
                foreach (var item in ltsMenuGroups)
                {
                    item.IsShow = false;
                    stbMessage.AppendFormat("Đã ẩn <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                _menuGroupsDa.Save();
                msg.ID      = string.Join(",", ltsMenuGroups.Select(o => o.Id));
                msg.Message = stbMessage.ToString();
                break;
            }

            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }

            return(Json(msg, JsonRequestBehavior.AllowGet));
        }