public bool Editinfo(UpdateCategoryInput input) { var checkCategory = db.ArticleCategories.FirstOrDefault(a => a.Name == input.Name && a.ID != input.ID); if (checkCategory != null) { throw new UserFriendlyException("栏目名重复"); } var category = db.ArticleCategories.Find(input.ID); if (category == null) { throw new UserFriendlyException(LocalizationConst.NoExist); } category = input.MapTo(category); category.ModifyTime = DateTime.Now; category.ModifyIP = IPHelper.GetIPAddress; if (!input.Attach.ID.HasValue || input.Attach.ID == 0) { var attach = db.ArticleAttaches.FirstOrDefault(a => a.ArticleGuid == category.Guid && a.ModuleType == (int)AttachTypesEnum.文章分类图片); if (attach != null) { db.ArticleAttaches.Remove(attach); } if (input.Attach.ID.HasValue && input.Attach.ID == 0) { db.ArticleAttaches.Add(new ArticleAttach() { HashValue = input.Attach.HashValue, ArticleGuid = category.Guid, AttachName = input.Attach.AttachName, AttachNewName = input.Attach.AttachNewName, AttachUrl = input.Attach.AttachUrl, AttachFormat = input.Attach.AttachFormat, AttachIndex = 1, AttachBytes = input.Attach.AttachBytes, AttachType = input.Attach.AttachType, ModuleType = (int)AttachTypesEnum.文章分类图片, CreateTime = DateTime.Now, CreateUser = input.ModifyUser, CreateIP = IPHelper.GetIPAddress }); } } db.Entry(category).State = EntityState.Modified; return(db.SaveChanges() > 0); }
public async Task UpdateCategory(UpdateCategoryInput input) { var category = await _categoryRepository.GetAsync(input.Id); input.MapTo(category); await _categoryRepository.UpdateAsync(category); }