// GET: Admin/JobCategories/Edit/5 public async Task <IActionResult> Edit(int?id) { var vm = new JobCategoryIM { Active = true, Importance = 0 }; if (id == null) { return(View(vm)); } var category = await _context.JobCategories.FindAsync(id); if (category == null) { return(NotFound()); } var model = _mapper.Map <JobCategoryIM>(category); var pm = await _context.PageMetas.FirstOrDefaultAsync(d => d.ModuleType == (short)ModuleType.ARTICLECATEGORY && d.ObjectId == category.Alias); if (pm != null) { model.SEOTitle = pm.Title; model.SEOKeywords = pm.Keywords; model.SEODescription = pm.Description; } return(View(model)); }
public async Task <IActionResult> Edit([Bind("Id,Title,Alias,Description,Importance,Active,SEOTitle,SEOKeywords,SEODescription")] JobCategoryIM im, int id = 0) { if (!ModelState.IsValid) { AR.Setfailure(GetModelErrorMessage()); return(Json(AR)); } if (id == 0) { var model = _mapper.Map <JobCategory>(im); model.CreatedBy = User.Identity.Name; model.CreatedDate = DateTime.Now; _context.Add(model); await _context.SaveChangesAsync(); // return RedirectToAction(nameof(Index)); AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.JobCategory)); return(Json(AR)); } if (id != im.Id) { AR.Setfailure("未发现此分类"); return(Json(AR)); } try { var model = await _context.JobCategories.FindAsync(id); model = _mapper.Map(im, model); model.UpdatedBy = User.Identity.Name; model.UpdatedDate = DateTime.Now; _context.Update(model); await _context.SaveChangesAsync(); //var pm = new PageMeta //{ // Title = im.SEOTitle, // Description = im.SEODescription, // Keywords = im.SEOKeywords, // ModuleType = (short)ModuleType.ARTICLECATEGORY, // ObjectId = im.Alias //}; //await CreatedUpdatedPageMetaAsync(_context, pm); AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.JobCategory)); return(Json(AR)); } catch (DbUpdateConcurrencyException) { if (!JobCategoryExists(im.Id)) { AR.Setfailure("未发现此分类"); return(Json(AR)); } else { AR.Setfailure(string.Format(Messages.AlertUpdateFailure, EntityNames.JobCategory)); return(Json(AR)); } } }