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

            try
            {
                var pictureId = Convert.ToInt32(Request["Value_DefaultImages"]);
                if (key != Keyapi)
                {
                    return(Json(0, JsonRequestBehavior.AllowGet));
                }
                UpdateModel(model);
                model.IsDeleted   = false;
                model.LanguageId  = "vi";
                model.DateCreated = DateTime.Now;
                model.DateUpdated = DateTime.Now;
                if (pictureId > 0)
                {
                    model.PictureID = pictureId;
                }
                model.Title          = HttpUtility.UrlDecode(model.Title);
                model.Description    = HttpUtility.UrlDecode(model.Description);
                model.Details        = HttpUtility.UrlDecode(model.Details);
                model.SEOTitle       = HttpUtility.UrlDecode(model.SEOTitle);
                model.SEODescription = HttpUtility.UrlDecode(model.SEODescription);
                model.SEOKeyword     = HttpUtility.UrlDecode(model.SEOKeyword);
                _da.Add(model);
                _da.Save();
                return(Json(model.ID, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(0, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 2
0
        public ActionResult Actions()
        {
            var msg   = new JsonMessage();
            var model = new News_News();
            List <News_News> ltsNewsItems;
            StringBuilder    stbMessage;
            List <Category>  lstCategory;
            var lsttag     = Request["values-arr-tag"];
            var images     = Request["Value_DefaultImages"];
            var lstCate    = Request["Value_CategoryValues"];
            var datecreate = Request["DateCreated_"];

            switch (DoAction)
            {
            case ActionType.Add:
                try
                {
                    UpdateModel(model);
                    model.LanguageId = Fdisystem.LanguageId;
                    //model.Viewer = 0;
                    var membershipUser = Membership.GetUser();
                    //model.TitleAscii = FomatString.Slug(model.Title);

                    if (membershipUser != null)
                    {
                        model.Author = membershipUser.UserName;
                    }
                    model.DateCreated = !string.IsNullOrEmpty(datecreate) ? ConvertUtil.ToDateTime(datecreate) : DateTime.Now;
                    if (!string.IsNullOrEmpty(lstCate))
                    {
                        var lstInt = FDIUtils.StringToListInt(lstCate);
                        model.Categories = _newsDa.GetListCategory(lstInt);
                    }
                    if (!string.IsNullOrEmpty(images))
                    {
                        model.PictureID = int.Parse(images);
                    }

                    if (!string.IsNullOrEmpty(lsttag))
                    {
                        var lstInt = FDIUtils.StringToListInt(lsttag);
                        model.System_Tag = _newsDa.GetListIntTagByArrID(lstInt);
                    }
                    model.IsDeleted = false;
                    _newsDa.Add(model);
                    _newsDa.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = model.ID.ToString(),
                        Message = string.Format("Đã thêm mới bài viết: <b>{0}</b>", Server.HtmlEncode(model.Title))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }

                break;

            case ActionType.Edit:
                try
                {
                    model = _newsDa.GetById(ArrId.FirstOrDefault());
                    UpdateModel(model);
                    //model.TitleAscii = FomatString.Slug(model.Title);
                    model.DateCreated = !string.IsNullOrEmpty(datecreate) ? ConvertUtil.ToDateTime(datecreate) : DateTime.Now;
                    var membershipUser = Membership.GetUser();
                    if (membershipUser != null)
                    {
                        var providerUserKey = membershipUser.ProviderUserKey;
                        if (providerUserKey != null)
                        {
                            model.Modifier = (Guid)providerUserKey;
                        }
                    }
                    model.Categories.Clear();
                    if (!string.IsNullOrEmpty(lstCate))
                    {
                        var lstInt = FDIUtils.StringToListInt(lstCate);
                        model.Categories = _newsDa.GetListCategory(lstInt);
                    }
                    if (!string.IsNullOrEmpty(images))
                    {
                        model.PictureID = int.Parse(images);
                    }

                    model.System_Tag.Clear();
                    if (!string.IsNullOrEmpty(lsttag))
                    {
                        var lstInt = FDIUtils.StringToListInt(lsttag);
                        model.System_Tag = _newsDa.GetListIntTagByArrID(lstInt);
                    }
                    //model.DateUpdated = DateTime.Now;
                    _newsDa.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = model.ID.ToString(),
                        Message = string.Format("Đã cập nhật bài viết: <b>{0}</b>", Server.HtmlEncode(model.Title))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }

                break;

            case ActionType.Delete:
                ltsNewsItems = _newsDa.GetListByArrID(ArrId);
                stbMessage   = new StringBuilder();
                foreach (var item in ltsNewsItems)
                {
                    try
                    {
                        item.IsDeleted = true;
                        stbMessage.AppendFormat("Đã xóa bài viết <b>{0}</b>.<br />", Server.HtmlEncode(item.Title));
                        _newsDa.Save();
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Instance.LogError(GetType(), ex);
                    }
                }
                msg.ID = string.Join(",", ArrId);
                _newsDa.Save();
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Show:
                ltsNewsItems = _newsDa.GetListByArrID(ArrId).Where(o => o.IsShow != true).ToList();     //Chỉ lấy những đối tượng ko được hiển thị
                stbMessage   = new StringBuilder();
                foreach (var item in ltsNewsItems)
                {
                    try
                    {
                        var providerUserKey = Membership.GetUser().ProviderUserKey;
                        if (providerUserKey != null)
                        {
                            item.Modifier = (Guid)providerUserKey;
                        }
                        item.IsShow = true;
                        stbMessage.AppendFormat("Đã hiển thị bài viết <b>{0}</b>.<br />", Server.HtmlEncode(item.Title));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Instance.LogError(GetType(), ex);
                    }
                }

                _newsDa.Save();
                msg.ID      = string.Join(",", ltsNewsItems.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Hide:
                ltsNewsItems = _newsDa.GetListByArrID(ArrId).Where(o => o.IsShow == true).ToList();     //Chỉ lấy những đối tượng được hiển thị
                stbMessage   = new StringBuilder();
                foreach (var item in ltsNewsItems)
                {
                    try
                    {
                        var providerUserKey = Membership.GetUser().ProviderUserKey;
                        if (providerUserKey != null)
                        {
                            item.Modifier = (Guid)providerUserKey;
                        }
                        item.IsShow = false;
                        stbMessage.AppendFormat("Đã ẩn bài viết <b>{0}</b>.<br />", Server.HtmlEncode(item.Title));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Instance.LogError(GetType(), ex);
                    }
                }

                _newsDa.Save();
                msg.ID      = string.Join(",", ltsNewsItems.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));
        }