Пример #1
0
        public ActionResult Detail(int?Id)
        {
            string cookieLanguage = "1";

            if (Request.Cookies["cookieLanguage"] != null)
            {
                cookieLanguage = Request.Cookies["cookieLanguage"].Value.ToString();
            }
            int.TryParse(cookieLanguage, out _languageId);
            modelAnPhamTaiLieu entity;

            if (Id.HasValue && Id > 0)
            {
                var model = _services.GetById(Id.Value);
                entity = new modelAnPhamTaiLieu
                {
                    Id              = model.contentId,
                    Alias           = model.contentAlias,
                    BodyContent     = model.contentBody,
                    CreateTime      = model.updateTime.ToString("dd/MM/yyyy"),
                    Img             = model.contentThumbnail,
                    LanguageId      = model.languageId,
                    MetaDescription = model.contentDescription,
                    MetaKeywords    = model.contentKeywords,
                    MetaTitle       = model.contentTitle,
                    Name            = model.contentName,
                    Note            = model.note,
                    ParentId        = model.parentId,
                    Sort            = model.isSort,
                    TacGia          = model.tacGia
                };
                ViewBag.Title = "Cập nhật ấn phẩm tài liệu";
            }
            else
            {
                entity = new modelAnPhamTaiLieu
                {
                    CreateTime = DateTime.Now.ToString("dd/MM/yyyy"),
                    LanguageId = _languageId
                };
                ViewBag.Title = "Thêm mới ấn phẩm tài liệu";
            }
            var category = _services.Dropdownlist(0, entity.Id, "canphamtailieu", _languageId);

            ViewBag.ParentId = category.Select(x => new SelectListItem {
                Text = x.Text, Value = x.Value.ToString()
            });
            return(View(entity));
        }
Пример #2
0
        public ActionResult Detail(modelAnPhamTaiLieu entity)
        {
            if (ModelState.IsValid)
            {
                if (entity.Id > 0)
                {
                    var model = _services.GetById(entity.Id);
                    if (entity.Alias.Contains("-" + entity.Id))
                    {
                        model.contentAlias = entity.Alias;
                    }
                    else
                    {
                        model.contentAlias = entity.Alias + "-" + entity.Id;
                    }
                    model.contentBody        = entity.BodyContent;
                    model.contentDescription = entity.MetaDescription;
                    model.contentId          = entity.Id;
                    model.contentThumbnail   = entity.Img;
                    model.contentTitle       = entity.MetaTitle;
                    if (string.IsNullOrEmpty(entity.CreateTime))
                    {
                        model.updateTime = DateTime.Now;
                    }
                    else
                    {
                        model.updateTime = DateTime.ParseExact(entity.CreateTime, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    }
                    model.parentId    = entity.ParentId;
                    model.note        = entity.Note;
                    model.contentName = entity.Name;
                    model.isSort      = entity.Sort;
                    model.tacGia      = entity.TacGia;
                    model.contentKey  = "AnPhamTaiLieu";
                    _services.Update(model);
                    _services.Save();
                    _serviceLog.Add(new ActionLog {
                        actionLogStatus = 1, actionLogTime = DateTime.Now, actionLogType = 1, actionNote = "Cấp nhật Ấn phẩm tài liệu Id:" + model.contentId + ":" + model.contentName, userIp = "", userName = User.Identity.Name
                    });
                    _serviceLog.Save();
                }
                else
                {
                    var model = new Content();
                    model.contentAlias       = entity.Alias;
                    model.contentBody        = entity.BodyContent;
                    model.contentDescription = entity.MetaDescription;
                    model.contentId          = entity.Id;
                    model.contentThumbnail   = entity.Img;
                    model.contentTitle       = entity.MetaTitle;
                    if (string.IsNullOrEmpty(entity.CreateTime))
                    {
                        model.updateTime = DateTime.Now;
                    }
                    else
                    {
                        model.updateTime = DateTime.ParseExact(entity.CreateTime, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    }
                    model.parentId    = entity.ParentId;
                    model.note        = entity.Note;
                    model.contentName = entity.Name;
                    model.createTime  = DateTime.Now; model.ngayBanHanh = DateTime.Now;
                    model.isSort      = entity.Sort;
                    model.isTrash     = false;
                    model.isView      = 0;
                    model.tacGia      = entity.TacGia;
                    model.languageId  = entity.LanguageId;
                    model.contentKey  = "AnPhamTaiLieu";
                    model.approval    = false;
                    _services.Add(model);
                    _services.Save();
                    model.contentAlias = model.contentAlias + "-" + model.contentId;
                    _services.Update(model);
                    _services.Save();
                    _serviceLog.Add(new ActionLog {
                        actionLogStatus = 1, actionLogTime = DateTime.Now, actionLogType = 1, actionNote = "Thêm mới Ấn phẩm tài liệu Id:" + model.contentId + ":" + model.contentName, userIp = "", userName = User.Identity.Name
                    });
                    _serviceLog.Save();
                }
                return(RedirectToAction("Index", new { _parentId = entity.ParentId }));
            }
            var category = _services.Dropdownlist(0, entity.Id, "canphamtailieu", entity.LanguageId);

            ViewBag.ParentId = category.Select(x => new SelectListItem {
                Text = x.Text, Value = x.Value.ToString()
            });
            return(View(entity));
        }