Esempio n. 1
0
        public ActionResult Detail(int?Id)
        {
            ModelTaiLieu entity;

            if (Id.HasValue && Id > 0)
            {
                Content model = _services.GetById(Id.Value);
                entity = new ModelTaiLieu
                {
                    Id              = (int)model.contentId,
                    Alias           = model.contentAlias,
                    BodyContent     = model.contentBody,
                    CreateTime      = model.contentUpdateTime.ToString("dd/MM/yyyy"),
                    Img             = model.contentThumbnail,
                    LanguageId      = 1,
                    MetaDescription = model.contentDescription,
                    MetaKeywords    = model.contentMetaKeywords,
                    MetaTitle       = model.contentMetaTitle,
                    Name            = model.contentName,
                    Note            = model.contentDescription,
                    ParentId        = (int)model.contentParentId,
                    Sort            = model.isSort,
                    TacGia          = model.authorize
                };
                ViewBag.Title = "Cập nhật văn bản";
            }
            else
            {
                entity = new ModelTaiLieu
                {
                    CreateTime = DateTime.Now.ToString("dd/MM/yyyy"),
                    LanguageId = 1
                };
                ViewBag.Title = "Thêm mới văn bản";
            }
            IEnumerable <DropdownModel> category = _services.Dropdownlist(0, (int)entity.Id, "CHUYENMUCTAILIEU", 1);

            ViewBag.ParentId = category.Select(x => new SelectListItem {
                Text = x.Text, Value = x.Value.ToString()
            });
            return(View(entity));
        }
Esempio n. 2
0
        public ActionResult Detail(ModelTaiLieu entity)
        {
            if (ModelState.IsValid)
            {
                if (entity.Id > 0)
                {
                    Content model = _services.GetById((int)entity.Id);
                    model.contentAlias       = entity.Alias;
                    model.contentBody        = entity.BodyContent;
                    model.contentDescription = entity.MetaDescription;
                    model.contentId          = entity.Id;
                    model.contentThumbnail   = entity.Img;
                    model.contentMetaTitle   = entity.MetaTitle;
                    if (string.IsNullOrEmpty(entity.CreateTime))
                    {
                        model.contentUpdateTime = DateTime.Now;
                    }
                    else
                    {
                        model.contentUpdateTime = DateTime.ParseExact(entity.CreateTime, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    }

                    model.contentParentId    = entity.ParentId;
                    model.authorize          = entity.TacGia;
                    model.contentDescription = entity.Note;
                    model.contentName        = entity.Name;
                    model.isSort             = entity.Sort;
                    _services.Update(model);
                    _services.Save();
                }
                else
                {
                    Content model = new Content
                    {
                        contentAlias       = entity.Alias,
                        contentBody        = entity.BodyContent,
                        contentDescription = entity.MetaDescription,
                        contentId          = entity.Id,
                        contentThumbnail   = entity.Img,
                        contentMetaTitle   = entity.MetaTitle
                    };
                    if (string.IsNullOrEmpty(entity.CreateTime))
                    {
                        model.contentUpdateTime = DateTime.Now;
                    }
                    else
                    {
                        model.contentUpdateTime = DateTime.ParseExact(entity.CreateTime, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    }

                    model.contentParentId    = entity.ParentId;
                    model.contentDescription = entity.Note;
                    model.contentName        = entity.Name;
                    model.contentCreateTime  = DateTime.Now;
                    model.isSort             = entity.Sort;
                    model.isTrash            = false;
                    model.contentView        = 0;
                    model.authorize          = entity.TacGia;
                    model.contentLanguageId  = 1;
                    model.contentKey         = "DOCUMENT";
                    _services.Add(model);
                    _services.Save();
                    model.contentAlias = model.contentAlias + "-" + model.contentId;
                    _services.Update(model);
                    _services.Save();
                }
                return(RedirectToAction("Index", new { _parentId = entity.ParentId }));
            }
            IEnumerable <DropdownModel> category = _services.Dropdownlist(0, (int)entity.Id, "CHUYENMUCTAILIEU", 1);

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