// GET: Admin/Staffs/Edit/5 public async Task <IActionResult> Edit(int?id) { var vm = new StaffIM(); if (id == null) { vm.Active = true; } else { var article = await _context.Staffs.FindAsync(id); if (article == null) { return(NotFound()); } vm = _mapper.Map <StaffIM>(article); var pm = await _context.PageMetas.FirstOrDefaultAsync(d => d.ModuleType == (short)ModuleType.STAFF && d.ObjectId == vm.Id.ToString()); if (pm != null) { vm.SEOTitle = pm.Title; vm.SEOKeywords = pm.Keywords; vm.SEODescription = pm.Description; } } var categories = await _context.Organizations.AsNoTracking() .OrderByDescending(d => d.Importance).ToListAsync(); ViewData["Categories"] = new SelectList(categories, "Id", "Title"); return(View(vm)); }
public async Task <IActionResult> Edit(StaffIM 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.STAFF }; if (article.Id > 0) { var model = await _context.Staffs.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; _context.Entry(model).State = EntityState.Modified; await _context.SaveChangesAsync(); AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.Staff)); pm.ObjectId = model.Id.ToString(); } else { var model = _mapper.Map <Staff>(article); model.CreatedBy = User.Identity.Name; model.CreatedDate = DateTime.Now; //model.Body = WebUtility.HtmlEncode(page.Body); _context.Add(model); await _context.SaveChangesAsync(); pm.ObjectId = model.Id.ToString(); AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Staff)); } await CreatedUpdatedPageMetaAsync(_context, pm); return(Json(AR)); } catch (DbUpdateConcurrencyException) { if (!StaffExists(article.Id)) { AR.Setfailure(Messages.HttpNotFound); return(Json(AR)); } else { throw; } } }