public JsonResult Edit(DocumentIM vm) { if (!ModelState.IsValid) { AR.Setfailure(GetModelErrorMessage()); return(Json(AR, JsonRequestBehavior.DenyGet)); } try { var doc = _documentServices.GetById(vm.Id); var editDocument = _mapper.Map(vm, doc); var filePath = Server.MapPath(vm.FilePath); var finfo = new FileInfo(filePath); long length = finfo.Length; editDocument.FileSize = length / 1024; editDocument.Extension = finfo.Extension.Remove(0, 1); _documentServices.Update(editDocument); //var pageMeta = _pageMetaServices.GetPageMeta(ModelType.Document, editDocument.Id.ToString()); //pageMeta = pageMeta ?? new PageMeta(); //pageMeta.ObjectId = vm.Id.ToString(); //pageMeta.Title = string.IsNullOrEmpty(vm.SEOTitle) ? vm.Title : vm.SEOTitle; //pageMeta.Keyword = string.IsNullOrEmpty(vm.Keywords) ? vm.Title : vm.Keywords.Replace(',', ','); //pageMeta.Description = vm.SEODescription; //pageMeta.ModelType = ModelType.Document; //if (pageMeta.Id > 0) //{ // _pageMetaServices.Update(pageMeta); //} //else //{ // _pageMetaServices.Create(pageMeta); //} AR.SetSuccess(String.Format(Messages.AlertUpdateSuccess, EntityNames.Document)); return(Json(AR, JsonRequestBehavior.DenyGet)); } catch (Exception er) { AR.Setfailure(er.Message); return(Json(AR, JsonRequestBehavior.DenyGet)); } }
public ActionResult Add() { var Document = new DocumentIM { Active = true, IsVIP = false }; var categorys = _categoryServices.GetAll().OrderByDescending(m => m.Importance).ToList(); var lCategorys = new SelectList(categorys, "Id", "Title"); ViewBag.Categories = lCategorys; var exts = new SelectList(Infrastructure.Helper.FileHelper.GetExtensions(), "Value", "Text"); ViewBag.Extensions = exts; return(View(Document)); }
public JsonResult Add(DocumentIM vm) { if (!ModelState.IsValid) { AR.Setfailure(GetModelErrorMessage()); return(Json(AR, JsonRequestBehavior.DenyGet)); } try { var newDocument = _mapper.Map <DocumentIM, Document>(vm); var filePath = Server.MapPath(vm.FilePath); var finfo = new FileInfo(filePath); long length = finfo.Length; newDocument.FileSize = length / 1024; newDocument.Extension = finfo.Extension.Remove(0, 1); var result = _documentServices.Create(newDocument); //if (result != null) //{ // var pageMeta = new PageMeta() // { // ObjectId = result.ToString(), // Title = string.IsNullOrEmpty(vm.SEOTitle) ? vm.Title : vm.SEOTitle, // Keyword = string.IsNullOrEmpty(vm.Keywords) ? vm.Title : vm.Keywords.Replace(',', ','), // Description = vm.SEODescription, // ModelType = ModelType.Document // }; // _pageMetaServices.Create(pageMeta); //} AR.SetSuccess(String.Format(Messages.AlertCreateSuccess, EntityNames.Document)); return(Json(AR, JsonRequestBehavior.DenyGet)); } catch (Exception er) { AR.Setfailure(er.Message); return(Json(AR, JsonRequestBehavior.DenyGet)); } }
// GET: Admin/Documents/Edit/5 public async Task <IActionResult> Edit(int?id) { var vm = new DocumentIM(); if (id == null) { vm.Active = true; vm.PubDate = DateTime.Now; } else { var article = await _context.Documents.FindAsync(id); if (article == null) { return(NotFound()); } vm = _mapper.Map <DocumentIM>(article); //var pm = await _context.PageMetas.FirstOrDefaultAsync(d => d.ModuleType == (short)ModuleType.ARTICLE && d.ObjectId == vm.Id.ToString()); //if (pm != null) //{ // vm.SEOTitle = pm.Title; // vm.SEOKeywords = pm.Keywords; // vm.SEODescription = pm.Description; //} } var categories = await _context.DocCategories.AsNoTracking() .OrderByDescending(d => d.Importance).ToListAsync(); ViewData["Categories"] = new SelectList(categories, "Id", "Title"); return(View(vm)); }
public async Task <IActionResult> Edit(DocumentIM article) { if (!ModelState.IsValid) { AR.Setfailure(GetModelErrorMessage()); return(Json(AR)); } try { //var pm = new PageMeta //{ // Title = article.SEOTitle, // Description = article.SEODescription, // Keywords = article.SEOKeywords, // ModuleType = (short)ModuleType.ARTICLE //}; string webRootPath = _hostingEnvironment.WebRootPath; if (article.Id > 0) { var model = await _context.Documents.FirstOrDefaultAsync(d => d.Id == article.Id); if (model == null) { AR.Setfailure(Messages.HttpNotFound); return(Json(AR)); } model = _mapper.Map(article, model); model.UpdatedBy = User.Identity.Name; model.UpdatedDate = DateTime.Now; string filePath = webRootPath + model.FileUrl; if (System.IO.File.Exists(filePath)) { var fz = await System.IO.File.ReadAllBytesAsync(filePath); model.FileSize = fz.Length; } _context.Entry(model).State = EntityState.Modified; await _context.SaveChangesAsync(); AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.Document)); // pm.ObjectId = model.Id.ToString(); } else { var model = _mapper.Map <Document>(article); model.CreatedBy = User.Identity.Name; model.CreatedDate = DateTime.Now; string filePath = webRootPath + model.FileUrl; if (System.IO.File.Exists(filePath)) { var fz = await System.IO.File.ReadAllBytesAsync(filePath); model.FileSize = fz.Length; } //model.Body = WebUtility.HtmlEncode(page.Body); _context.Add(model); await _context.SaveChangesAsync(); //pm.ObjectId = model.Id.ToString(); AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Document)); } //await CreatedUpdatedPageMetaAsync(_context, pm); return(Json(AR)); } catch (DbUpdateConcurrencyException) { if (!DocumentExists(article.Id)) { AR.Setfailure(Messages.HttpNotFound); return(Json(AR)); } else { throw; } } }