Пример #1
0
 public ActionResult Delete(string key, string lstArrId)
 {
     if (key == Keyapi)
     {
         var lstInt = FDIUtils.StringToListInt(lstArrId);
         var lst    = _da.GetListByArrId(lstInt);
         foreach (var item in lst)
         {
             _da.Delete(item);
         }
         _da.Save();
         return(Json(1, JsonRequestBehavior.AllowGet));
     }
     return(Json(0, JsonRequestBehavior.AllowGet));
 }
Пример #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));
        }