// GET: Admin/Clients/Edit/5 public async Task <IActionResult> Edit(int?id) { var vm = new ClientIM { Active = true, Importance = 0 }; if (id == null) { return(View(vm)); } var category = await _context.Clients.FindAsync(id); if (category == null) { return(NotFound()); } var model = _mapper.Map <ClientIM>(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,ClientName,LogoURL,Importance,Active,SEOTitle,SEOKeywords,SEODescription")] ClientIM im, int id = 0) { if (!ModelState.IsValid) { AR.Setfailure(GetModelErrorMessage()); return(Json(AR)); } if (id == 0) { var model = _mapper.Map <Client>(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.Client)); return(Json(AR)); } if (id != im.Id) { AR.Setfailure("未发现此分类"); return(Json(AR)); } try { var model = await _context.Clients.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.Client)); return(Json(AR)); } catch (DbUpdateConcurrencyException) { if (!ClientExists(im.Id)) { AR.Setfailure("未发现此分类"); return(Json(AR)); } else { AR.Setfailure(string.Format(Messages.AlertUpdateFailure, EntityNames.Client)); return(Json(AR)); } } }