public JsonResult Add(LinkCategoryIM vm) { if (!ModelState.IsValid) { AR.Setfailure(GetModelErrorMessage()); return(Json(AR, JsonRequestBehavior.DenyGet)); } var newCategory = _mapper.Map <LinkCategoryIM, LinkCategory>(vm); var result = _categoryServices.Create(newCategory); 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.LINKCATEGORY }; _pageMetaServices.Create(pageMeta); } int count; var pageSize = SettingsManager.Link.PageSize; var list = _categoryServices.GetPagedElements(0, pageSize, string.Empty, out count); AR.Data = RenderPartialViewToString("_CategoryList", list); AR.SetSuccess(String.Format(Messages.AlertCreateSuccess, EntityNames.LinkCategory)); return(Json(AR, JsonRequestBehavior.DenyGet)); }
public ActionResult Add() { var vCategory = new LinkCategoryIM() { Active = true, Importance = 0 }; return(PartialView("_Add", vCategory)); }
public async Task CreateCategoryAsync(LinkCategoryIM item) { var category = _mapper.Map <LinkCategory>(item); category.CreatedDate = DateTime.Now; category.CreatedBy = await _sessionStorageService.GetItemAsync <string>("username"); await _db.AddAsync(category); await _db.SaveChangesAsync(); }
public async Task UpdateCategoryAsync(int id, LinkCategoryIM item) { var origin = await _db.LinkCategories.FindAsync(id); var category = _mapper.Map(item, origin); category.UpdatedDate = DateTime.Now; category.UpdatedBy = await _sessionStorageService.GetItemAsync <string>("username"); _db.Update(category); await _db.SaveChangesAsync(); }
public async Task <IActionResult> PostLinkCategory([FromBody] LinkCategoryIM linkCategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var model = _mapper.Map <LinkCategory>(linkCategory); _context.LinkCategories.Add(model); await _context.SaveChangesAsync(); return(Ok("链接分类创建成功")); }
public JsonResult Edit(LinkCategoryIM vm) { if (!ModelState.IsValid) { AR.Setfailure(GetModelErrorMessage()); return(Json(AR, JsonRequestBehavior.DenyGet)); } var old = _categoryServices.GetById(vm.Id); var newCategory = _mapper.Map(vm, old); _categoryServices.Update(newCategory); var pageMeta = _pageMetaServices.GetPageMeta(ModelType.ARTICLECATEGORY, vm.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.ARTICLECATEGORY; if (pageMeta.Id > 0) { _pageMetaServices.Update(pageMeta); } else { _pageMetaServices.Create(pageMeta); } // var category = _mapper.Map<LinkCategoryVM>(newCategory); AR.Id = newCategory.Id; AR.Data = RenderPartialViewToString("_CategoryItem", newCategory); AR.SetSuccess(String.Format(Messages.AlertUpdateSuccess, EntityNames.LinkCategory)); return(Json(AR, JsonRequestBehavior.DenyGet)); }
public async Task <IActionResult> PutLinkCategory([FromRoute] int id, [FromBody] LinkCategoryIM linkCategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != linkCategory.Id) { return(BadRequest()); } var model = await _context.LinkCategories.FirstOrDefaultAsync(d => d.Id == id); model = _mapper.Map(linkCategory, model); _context.Entry(model).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LinkCategoryExists(id)) { return(NotFound()); } else { throw; } } return(Ok("链接分类更新成功")); }