// GET: Admin/Albums/Edit/5 public async Task <IActionResult> Edit(int?id) { var vm = new AlbumIM { Active = true, Importance = 0 }; if (id == null) { return(View(vm)); } var category = await _context.Albums.FindAsync(id); if (category == null) { return(NotFound()); } var model = _mapper.Map <AlbumIM>(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 <ActionResult> Edit([Bind(Include = "Id,Title,Importance,Cover,Banner,Active")] AlbumIM album) { if (!ModelState.IsValid) { AR.Setfailure(GetModelErrorMessage()); return(Json(AR, JsonRequestBehavior.DenyGet)); } if (album.Id > 0) { var model = await _db.Albums.FindAsync(album.Id); model = _mapper.Map(album, model); model.UpdatedBy = Site.CurrentUserName; model.UpdatedDate = DateTime.Now; _db.Entry(model).State = EntityState.Modified; await _db.SaveChangesAsync(); var message = string.Format(Messages.AlertUpdateSuccess, EntityNames.Album); _logger.Info(message); AR.SetSuccess(message); return(Json(AR, JsonRequestBehavior.DenyGet)); } else { var im = _mapper.Map <Album>(album); im.CreatedBy = Site.CurrentUserName; im.CreatedDate = DateTime.Now; _db.Albums.Add(im); await _db.SaveChangesAsync(); var message = string.Format(Messages.AlertCreateSuccess, EntityNames.Album); _logger.Info(message); AR.SetSuccess(message); return(Json(AR, JsonRequestBehavior.DenyGet)); } }
public async Task <IActionResult> Edit([Bind("Id,Title,Alias,Cover,Description,Importance,Active")] AlbumIM im, int id = 0) { if (!ModelState.IsValid) { AR.Setfailure(GetModelErrorMessage()); return(Json(AR)); } if (id == 0) { var model = _mapper.Map <Album>(im); model.CreatedBy = User.Identity.Name; model.CreatedDate = DateTime.Now; _context.Add(model); await _context.SaveChangesAsync(); // return RedirectToAction(nameof(Index)); _cacheService.Invalidate("PHOTO"); _cacheService.Invalidate("ALBUM"); AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Album)); return(Json(AR)); } if (id != im.Id) { AR.Setfailure("未发现此分类"); return(Json(AR)); } try { var model = await _context.Albums.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); _cacheService.Invalidate("PHOTO"); _cacheService.Invalidate("ALBUM"); AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.Album)); return(Json(AR)); } catch (DbUpdateConcurrencyException) { if (!AlbumExists(im.Id)) { AR.Setfailure("未发现此分类"); return(Json(AR)); } else { AR.Setfailure(string.Format(Messages.AlertUpdateFailure, EntityNames.Album)); return(Json(AR)); } } }