public ResponseInfoModel EditInfo([FromBody] UpdateCategoryInput input)
        {
            ResponseInfoModel json = new ResponseInfoModel()
            {
                Success = 1, Result = new object()
            };

            try
            {
                if (!_articleCategoryService.Editinfo(input))
                {
                    json.Success = 0;
                    json.Result  = LocalizationConst.UpdateFail;
                }
                else
                {
                    _logService.Insert(new Log()
                    {
                        ActionContent = LocalizationConst.Update,
                        SourceType    = _moduleName,
                        SourceID      = input.ID,
                        LogTime       = DateTime.Now,
                        LogUserID     = input.ModifyUser,
                        LogIPAddress  = IPHelper.GetIPAddress,
                    });
                }
            }
            catch (Exception e)
            {
                DisposeUserFriendlyException(e, ref json, "api/category/editInfo", LocalizationConst.UpdateFail);
            }
            return(json);
        }
Beispiel #2
0
        public async Task UpdateCategory()
        {
            var options = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: "Test_UpdateCategory").Options;
            MapperConfiguration mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMapperProfile());
            });
            IMapper mapper = mappingConfig.CreateMapper();
            ApplicationResult <CategoryDto> resultCreate = new ApplicationResult <CategoryDto>();

            // bir yeni kategori olustur
            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                resultCreate = await CreateCategory(inMemoryContext, mapper);
            }

            ApplicationResult <CategoryDto> resultUpdate = new ApplicationResult <CategoryDto>();

            // yeni kategori olustu mu test et ve var olan kategoriyi guncelle
            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                // create servis duzgun calisti mi?
                Assert.True(resultCreate.Succeeded);
                Assert.NotNull(resultCreate.Result);
                // update islemini yap!

                var item = await inMemoryContext.Categories.FirstOrDefaultAsync();

                var service    = new CategoryService(inMemoryContext, mapper);
                var fakeUpdate = new UpdateCategoryInput
                {
                    Id           = item.Id,
                    CreatedById  = item.CreatedById,
                    ModifiedById = Guid.NewGuid().ToString(),
                    ModifiedBy   = "Tester2",
                    Name         = "Lorem Ipsum Dolor",
                    UrlName      = "lorem-ipsum-dolor"
                };
                // update servisi calistir
                resultUpdate = await service.Update(fakeUpdate);
            }
            // update basarili mi kontrol et
            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                // contextte kategori var mi?
                Assert.Equal(1, await inMemoryContext.Categories.CountAsync());
                // update servis duzgun calisti mi?
                Assert.True(resultUpdate.Succeeded);
                Assert.NotNull(resultUpdate.Result);
                // update islem basarili mi (context ten gelen veri ile string ifadeleri karsilastir)
                var item = await inMemoryContext.Categories.FirstAsync();

                Assert.Equal("Tester1", item.CreatedBy);
                Assert.Equal("Tester2", item.ModifiedBy);
                Assert.Equal("Lorem Ipsum Dolor", item.Name);
                Assert.Equal("lorem-ipsum-dolor", item.UrlName);
                Assert.Equal(resultUpdate.Result.ModifiedById, item.ModifiedById);
            }
        }
        public void UpdateCategory(UpdateCategoryInput input)
        {
            var cList = _categoryRepository.Get(input.CategoryId);

            cList.CategoryName = input.CategoryName;
            cList.Description  = input.Description;
            cList.ParentId     = input.ParentId;
            cList.PList        = _programListRepository.Load(input.ProgramListId);
        }
        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 <IActionResult> Update(int id)
        {
            var getService = await _categoryService.Get(id);

            UpdateCategoryInput input = new UpdateCategoryInput
            {
                Id           = getService.Result.Id,
                CreatedById  = getService.Result.CreatedById,
                ModifiedById = User.FindFirst(ClaimTypes.NameIdentifier).Value,
                Name         = getService.Result.Name,
                UrlName      = getService.Result.UrlName
            };

            return(View(input));
        }
Beispiel #6
0
        public async Task <BlogResponse> UpdateCategoryAsync(string id, UpdateCategoryInput input)
        {
            var response = new BlogResponse();

            var category = await _categories.FindAsync(id.ToObjectId());

            if (category is null)
            {
                response.IsFailed($"The category id not exists.");
                return(response);
            }

            category.Name  = input.Name;
            category.Alias = input.Alias;

            await _categories.UpdateAsync(category);

            return(response);
        }
        public async Task <ApplicationResult <CategoryDto> > Update(UpdateCategoryInput input)
        {
            try
            {
                var modifierUser = await _userManager.FindByIdAsync(input.ModifiedById);

                var getExistCategory = await _context.Categories.FindAsync(input.Id);

                getExistCategory.Name         = input.Name;
                getExistCategory.UrlName      = input.UrlName;
                getExistCategory.ModifiedBy   = modifierUser.UserName;
                getExistCategory.ModifiedById = modifierUser.Id;
                getExistCategory.ModifiedDate = DateTime.UtcNow;
                _context.Update(getExistCategory);
                await _context.SaveChangesAsync();

                return(new ApplicationResult <CategoryDto>
                {
                    Succeeded = true,
                    Result = new CategoryDto
                    {
                        CreatedBy = getExistCategory.CreatedBy,
                        CreatedById = getExistCategory.CreatedById,
                        CreatedDate = getExistCategory.CreatedDate,
                        Id = getExistCategory.Id,
                        ModifiedBy = getExistCategory.ModifiedBy,
                        ModifiedById = getExistCategory.ModifiedById,
                        ModifiedDate = getExistCategory.ModifiedDate,
                        Name = getExistCategory.Name,
                        UrlName = getExistCategory.UrlName
                    }
                });
            }
            catch (Exception ex)
            {
                return(new ApplicationResult <CategoryDto>
                {
                    Succeeded = false,
                    ErrorMessage = ex.Message,
                    Result = new CategoryDto()
                });
            }
        }
        public async Task <IActionResult> Update(int id, UpdateCategoryInput model)
        {
            if (ModelState.IsValid)
            {
                var getService = await _categoryService.Get(id);

                model.CreatedById  = getService.Result.CreatedById;
                model.Id           = getService.Result.Id;
                model.ModifiedById = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                var updateService = await _categoryService.Update(model);

                if (updateService.Succeeded)
                {
                    return(RedirectToAction("Details", new { id }));
                }
                ModelState.AddModelError(string.Empty, updateService.ErrorMessage);
            }
            return(View(model));
        }
Beispiel #9
0
        public async Task UpdateCategory(string id, UpdateCategoryInput input)
        {
            var category = await _categoryRepository.GetById(id);

            if (category == null)
            {
                throw new BusinessException("分类不存在!");
            }

            _mapper.Map(input, category);

            if (!string.IsNullOrWhiteSpace(input.ParentCategoryId))
            {
                var parentCategory = await _categoryRepository.GetById(input.ParentCategoryId);

                category.ParentCategory = parentCategory ?? throw new BusinessException("父分类不存在!");
            }

            await _categoryRepository.Update(category);
        }
Beispiel #10
0
        public void Update(UpdateCategoryInput input)
        {
            var output = ObjectMapper.Map <Category>(input);

            _categoryManager.Update(output);
        }
 public async Task Update(UpdateCategoryInput entity)
 {
     var category = Mapper.Map <UpdateCategoryInput, Category>(entity);
     await _categoryManger.Update(category);
 }
Beispiel #12
0
 public async Task UpdateCategory(UpdateCategoryInput input)
 {
     var category = await _categoryRepository.GetAsync(input.Id); input.MapTo(category); await _categoryRepository.UpdateAsync(category);
 }
        public async Task <IActionResult> UpdateCategory(string id, [FromBody] UpdateCategoryInput input)
        {
            await _categoryService.UpdateCategory(id, input);

            return(NoContent());
        }
Beispiel #14
0
        public void Update(UpdateCategoryInput input)
        {
            var category = _mapper.Map <Category>(input);

            _categoryManager.Update(category);
        }
 public Task <ApplicationResult <CategoryDto> > Update(UpdateCategoryInput input)
 {
     throw new NotImplementedException();
 }
        public void Update(UpdateCategoryInput input)
        {
            Category output = Mapper.Map <UpdateCategoryInput, Category>(input);

            _categoryManager.Update(output);
        }
Beispiel #17
0
        public async Task <ActionResult <ApplicationResult <CategoryDto> > > Put(int id, [FromBody] UpdateCategoryInput input)
        {
            if (ModelState.IsValid)
            {
                var getService = await _categoryService.Get(id);

                input.CreatedById = getService.Result.CreatedById;
                input.CreatedBy   = getService.Result.CreatedBy;

                input.Id           = getService.Result.Id;
                input.ModifiedById = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                input.ModifiedBy   = User.FindFirst(ClaimTypes.Name).Value;

                var updateService = await _categoryService.Update(input);

                if (updateService.Succeeded)
                {
                    return(Ok(updateService));
                }
                ModelState.AddModelError("Error", updateService.ErrorMessage);
            }
            return(BadRequest(new ApplicationResult <CategoryDto>
            {
                Result = new CategoryDto(),
                Succeeded = false,
                ErrorMessage = string.Join(", ", ModelState.Values)
            }));
        }