Esempio n. 1
0
        public ActionResult Delete(string key, string lstArrId)
        {
            var msg = new JsonMessage(false, "Xóa dữ liệu thành công !");

            try
            {
                if (key == Keyapi)
                {
                    var lst = _da.GetByListArrId(lstArrId);
                    foreach (var item in lst)
                    {
                        item.IsDeleted = true;
                    }
                    _da.Save();
                }
            }
            catch (Exception ex)
            {
                msg.Erros   = true;
                msg.Message = "Dữ liệu chưa được xóa.";
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public ActionResult Actions()
        {
            var msg      = new JsonMessage();
            var district = new System_District();
            List <System_District> ltsDistrictItems;
            StringBuilder          stbMessage;

            switch (DoAction)
            {
            case ActionType.Add:
                UpdateModel(district);
                _districtDa.Add(district);
                _districtDa.Save();
                msg = new JsonMessage
                {
                    Erros   = false,
                    ID      = district.ID.ToString(),
                    Message = string.Format("Đã thêm mới quận huyện: <b>{0}</b>", Server.HtmlEncode(district.Name))
                };
                break;

            case ActionType.Edit:
                district = _districtDa.GetById(ArrId.FirstOrDefault());
                UpdateModel(district);
                _districtDa.Save();
                msg = new JsonMessage
                {
                    Erros   = false,
                    ID      = district.ID.ToString(),
                    Message = string.Format("Đã cập nhật quận huyện: <b>{0}</b>", Server.HtmlEncode(district.Name))
                };
                break;

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

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

            case ActionType.Hide:
                ltsDistrictItems = _districtDa.GetByListArrId(ArrId).Where(o => o.IsShow).ToList();
                stbMessage       = new StringBuilder();
                foreach (var item in ltsDistrictItems)
                {
                    item.IsShow = false;
                    stbMessage.AppendFormat("Đã ẩn quận huyện <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                _districtDa.Save();
                msg.ID      = string.Join(",", ltsDistrictItems.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));
        }