public ActionResult Detail(int?Id) { modelDuThaoVanBanPhapLuat entity; string cookieLanguage = "1"; if (Request.Cookies["cookieLanguage"] != null) { cookieLanguage = Request.Cookies["cookieLanguage"].Value.ToString(); } int.TryParse(cookieLanguage, out int _languageId); if (Id.HasValue && Id > 0) { Content model = _services.GetById(Id.Value); entity = new modelDuThaoVanBanPhapLuat { 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 văn bản pháp luật"; } else { entity = new modelDuThaoVanBanPhapLuat { CreateTime = DateTime.Now.ToString("dd/MM/yyyy"), LanguageId = _languageId }; ViewBag.Title = "Thêm mới văn bản pháp luật"; } IEnumerable <DropdownModel> category = _services.Dropdownlist(0, entity.Id, "cduthaovanbanphapluat", _languageId); ViewBag.ParentId = category.Select(x => new SelectListItem { Text = x.Text, Value = x.Value.ToString() }); return(View(entity)); }
public ActionResult Detail(modelDuThaoVanBanPhapLuat entity) { if (ModelState.IsValid) { if (entity.Id > 0) { Content 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.contentKey = "Duthaovanbanphapluat"; model.isSort = entity.Sort; model.tacGia = entity.TacGia; _services.Update(model); _services.Save(); _serviceLog.Add(new ActionLog { actionLogStatus = 1, actionLogTime = DateTime.Now, actionLogType = 1, actionNote = "Cập nhật dự thảo văn bản pháp luật Id:" + model.contentId + ":" + model.contentName, userIp = "", userName = User.Identity.Name }); _serviceLog.Save(); } else { Content model = new Content { contentAlias = entity.Alias, contentBody = entity.BodyContent, contentDescription = entity.MetaDescription, contentId = entity.Id, contentThumbnail = entity.Img, 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.tacGia = entity.TacGia; model.isTrash = false; model.approval = false; model.isView = 0; model.languageId = entity.LanguageId; model.contentKey = "Duthaovanbanphapluat"; _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 dự thảo văn bản pháp luật Id:" + model.contentId + ":" + model.contentName, userIp = "", userName = User.Identity.Name }); _serviceLog.Save(); } return(RedirectToAction("Index", new { _parentId = entity.ParentId })); } IEnumerable <DropdownModel> category = _services.Dropdownlist(0, entity.Id, "cduthaovanbanphapluat", entity.LanguageId); ViewBag.ParentId = category.Select(x => new SelectListItem { Text = x.Text, Value = x.Value.ToString() }); return(View(entity)); }