예제 #1
0
        public async Task <IActionResult> Edit(CategoryEditViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }

                var request = new EditCategoryRequest(model.Id)
                {
                    RouteName   = model.RouteName,
                    Note        = model.Note,
                    DisplayName = model.DisplayName
                };

                await _categoryService.UpdateAsync(request);

                DeleteOpmlFile();
                return(Json(model));
            }
            catch (Exception e)
            {
                Logger.LogError(e, "Error Create Category.");

                ModelState.AddModelError("", e.Message);
                return(ServerError());
            }
        }
예제 #2
0
 public static Category ToCategoryModel(this EditCategoryRequest request)
 {
     return(new Category
     {
         Name = request.Name
     });
 }
예제 #3
0
        public async Task <ActionResult> EditGenre(int categoryId, [FromBody] EditCategoryRequest request)
        {
            var genreModel = request.ToCategoryModel();

            await _categoryService.Edit(categoryId, genreModel);

            return(Ok());
        }
예제 #4
0
        public async Task <IActionResult> Edit(EditCategoryRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(Failure());
            }

            return(await _categoryService.Edit(request));
        }
예제 #5
0
    public async Task <IActionResult> Update([NotEmpty] Guid id, EditCategoryRequest model)
    {
        var oc = await _mediator.Send(new UpdateCategoryCommand(id, model));

        if (oc == OperationCode.ObjectNotFound)
        {
            return(NotFound());
        }

        return(NoContent());
    }
예제 #6
0
        public async Task <IActionResult> Update([NotEmpty] Guid id, EditCategoryRequest model)
        {
            var oc = await _catService.UpdateAsync(id, model.DisplayName, model.RouteName, model.Note);

            if (oc == OperationCode.ObjectNotFound)
            {
                return(NotFound());
            }

            return(NoContent());
        }
예제 #7
0
        public async Task <IActionResult> EditCategory([FromBody] EditCategoryRequest editCategoryRequest)
        {
            var editedCategory = await _shopService.EditCategoryAsync(editCategoryRequest);

            if (!editedCategory.Success)
            {
                return(BadRequest(editedCategory.Errors));
            }

            return(Ok(editedCategory.Response));
        }
예제 #8
0
    public async Task Create_ValidModel()
    {
        var categoryController = CreateCategoryController();
        var model = new EditCategoryRequest
        {
            DisplayName = FakeData.ShortString2,
            RouteName   = FakeData.ShortString2,
            Note        = FakeData.ShortString1
        };

        var result = await categoryController.Create(model);

        Assert.IsInstanceOf <CreatedResult>(result);
    }
예제 #9
0
        public async Task <IActionResult> Edit([FromBody] EditCategoryRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var response = await _categoryService.EditAsync(request);

            if (!response.IsValid)
            {
                return(BadRequest(response.Message));
            }
            return(Ok(response));
        }
예제 #10
0
        public async Task <BaseResponse> EditAsync(EditCategoryRequest request)
        {
            var category = await _categoryRepository.GetAsync(category => category.Id == request.Id);

            if (category == null)
            {
                return(new BaseResponse("Category is not found"));
            }

            category.Name = request.Name;
            _categoryRepository.Update(category);
            await _unitOfWork.SaveChangesAsync();

            return(new BaseResponse());
        }
예제 #11
0
        public async Task <IActionResult> Edit(EditCategoryRequest request)
        {
            var category = _context.Categories.Where(i => i.Id == request.CategoryId).FirstOrDefault();

            if (category == null)
            {
                return(Failure());
            }
            if (category.IsDefault)
            {
                return(Failure());
            }
            category.Name = request.Name;
            await _context.SaveChangesAsync();

            return(Success(ConvertToVM(category)));
        }
예제 #12
0
        public async Task <BaseResponse> EditAsync(EditCategoryRequest request, int accountId)
        {
            var category = await _categoryRepository.GetAsync(category => category.Id == request.Id && category.AccountId == accountId);

            if (category == null)
            {
                return(new BaseResponse("Category is not found"));
            }

            category.Title         = request.Title;
            category.Description   = request.Description;
            category.PlannedBudget = request.PlannedBudget;
            _categoryRepository.Update(category);
            await _unitOfWork.SaveChangesAsync();

            return(new BaseResponse());
        }
예제 #13
0
        public async Task <IActionResult> Edit(CategoryEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var request = new EditCategoryRequest(model.Id)
            {
                RouteName   = model.RouteName,
                Note        = model.Note,
                DisplayName = model.DisplayName
            };

            await _categoryService.UpdateAsync(request);

            return(Ok(model));
        }
예제 #14
0
        public async Task Update_ValidModel()
        {
            _mockCategoryService
            .Setup(p => p.UpdateAsync(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult(OperationCode.Done));

            var categoryController = CreateCategoryController();
            var model = new EditCategoryRequest
            {
                DisplayName = FakeData.ShortString2,
                RouteName   = FakeData.ShortString2,
                Note        = FakeData.ShortString1
            };

            var result = await categoryController.Update(FakeData.Uid1, model);

            Assert.IsInstanceOf <NoContentResult>(result);
        }
예제 #15
0
    public async Task Update_NotFound()
    {
        _mockMediator
        .Setup(p => p.Send(It.IsAny <UpdateCategoryCommand>(), default))
        .Returns(Task.FromResult(OperationCode.ObjectNotFound));

        var categoryController = CreateCategoryController();
        var model = new EditCategoryRequest
        {
            DisplayName = FakeData.ShortString2,
            RouteName   = FakeData.ShortString2,
            Note        = FakeData.ShortString1
        };

        var result = await categoryController.Update(FakeData.Uid1, model);

        Assert.IsInstanceOf <NotFoundResult>(result);
    }
예제 #16
0
        public async Task UpdateAsync(EditCategoryRequest editCategoryRequest)
        {
            var cat = await _categoryRepository.GetAsync(editCategoryRequest.Id);

            if (null == cat)
            {
                return;
            }

            cat.RouteName   = editCategoryRequest.RouteName.Trim();
            cat.DisplayName = editCategoryRequest.DisplayName.Trim();
            cat.Note        = editCategoryRequest.Note.Trim();

            await _categoryRepository.UpdateAsync(cat);

            _cache.Remove(CacheDivision.General, "allcats");

            await _blogAudit.AddAuditEntry(EventType.Content, AuditEventId.CategoryUpdated, $"Category '{editCategoryRequest.Id}' updated.");
        }
예제 #17
0
        public async Task <ResponseResult <CategoryResponse> > EditCategoryAsync(EditCategoryRequest editCategory)
        {
            var editedCategory = await _shopRepository.EditCategoryAsync(editCategory.CategoryId, editCategory.NewRuTitle, editCategory.NewEnTitle);

            if (editedCategory == null)
            {
                return(new ResponseResult <CategoryResponse>
                {
                    Errors = new[] { "Category not found" }
                });
            }

            var mappedEditedCategory = _mapper.Map <CategoryResponse>(editedCategory);

            return(new ResponseResult <CategoryResponse>
            {
                Success = true,
                Response = mappedEditedCategory
            });
        }
예제 #18
0
        public Response UpdateCategory(EditCategoryRequest editCategoryRequest)
        {
            return(TryExecute(() =>
            {
                var cat = _categoryRepository.Get(editCategoryRequest.Id);
                if (null == cat)
                {
                    return new Response {
                        Message = $"CategoryEntity id {editCategoryRequest.Id} not found."
                    }
                }
                ;

                cat.Title = editCategoryRequest.Title;
                cat.DisplayName = editCategoryRequest.DisplayName;
                cat.Note = editCategoryRequest.Note;

                var rows = _categoryRepository.Update(cat);
                return new Response(rows > 0);
            }));
        }
예제 #19
0
        /// <summary>
        /// EditCategory
        /// </summary>
        /// <param name="request">EditCategoryRequest</param>
        /// <returns>bool</returns>
        public async Task <bool> EditCategory(EditCategoryRequest request)
        {
            bool result = false;

            try
            {
                var param = new UpdateCategoryParameter()
                {
                    id           = request.id,
                    nameCategory = request.nameCategory,
                    imgCategory  = request.imgCategory
                };
                _dataAccess.EditCategory(param);
                result = true;
                return(result);
            }
            catch (Exception)
            {
                result = false;
            }
            return(await Task.FromResult(result));
        }
예제 #20
0
        public async Task <CategoryResponse> EditCategoryAsync(EditCategoryRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException();
            }

            var categoryExists = await _categoryRepository.GetAsync(request.Id);

            if (categoryExists == null)
            {
                throw new ArgumentException("News with id {request.Id} does not exist");
            }

            var category = _mapper.Map <Entities.Category>(request);
            var result   = _categoryRepository.Update(category);
            await _categoryRepository.UnitOfWork.SaveChangesAsync();

            var response = _mapper.Map <CategoryResponse>(result);

            return(response);
        }
예제 #21
0
        public IActionResult Edit(CategoryEditViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var request = new EditCategoryRequest(model.Id)
                    {
                        Title       = model.Name,
                        Note        = model.Note,
                        DisplayName = model.DisplayName
                    };

                    var response = _categoryService.UpdateCategory(request);

                    if (response.IsSuccess)
                    {
                        DeleteOpmlFile();

                        _moongladeAudit.AddAuditEntry(EventType.Content, EventId.CategoryUpdated, $"Category '{model.Id}' is updated");
                        return(Json(response));
                    }

                    Logger.LogError($"Edit category failed: {response.Message}");
                    ModelState.AddModelError("", response.Message);
                    return(BadRequest());
                }

                return(BadRequest());
            }
            catch (Exception e)
            {
                Logger.LogError(e, "Error Create Category.");

                ModelState.AddModelError("", e.Message);
                return(ServerError());
            }
        }
예제 #22
0
        public Task <Response> UpdateAsync(EditCategoryRequest editCategoryRequest)
        {
            return(TryExecuteAsync(async() =>
            {
                var cat = await _categoryRepository.GetAsync(editCategoryRequest.Id);
                if (null == cat)
                {
                    return new Response {
                        Message = $"CategoryEntity id '{editCategoryRequest.Id}' not found."
                    }
                }
                ;

                cat.RouteName = editCategoryRequest.RouteName.Trim();
                cat.DisplayName = editCategoryRequest.DisplayName.Trim();
                cat.Note = editCategoryRequest.Note.Trim();

                await _categoryRepository.UpdateAsync(cat);
                await _moongladeAudit.AddAuditEntry(EventType.Content, AuditEventId.CategoryUpdated, $"Category '{editCategoryRequest.Id}' updated.");

                return new SuccessResponse();
            }));
        }
예제 #23
0
        public IActionResult Edit(CategoryEditViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var request = new EditCategoryRequest(model.Id)
                    {
                        Title       = model.Name,
                        Note        = model.Note,
                        DisplayName = model.DisplayName
                    };

                    var response = _categoryService.UpdateCategory(request);

                    if (response.IsSuccess)
                    {
                        DeleteOpmlFile();
                        return(RedirectToAction(nameof(Manage)));
                    }

                    Logger.LogError($"Edit category failed: {response.Message}");
                    ModelState.AddModelError("", response.Message);
                    return(View("CreateOrEdit", model));
                }

                return(View("CreateOrEdit", model));
            }
            catch (Exception e)
            {
                Logger.LogError(e, "Error Create Category.");

                ModelState.AddModelError("", e.Message);
                return(View("CreateOrEdit", model));
            }
        }
예제 #24
0
        public async Task <IActionResult> Edit(CategoryEditViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var request = new EditCategoryRequest(model.Id)
                    {
                        RouteName   = model.RouteName,
                        Note        = model.Note,
                        DisplayName = model.DisplayName
                    };

                    var response = await _categoryService.UpdateAsync(request);

                    if (response.IsSuccess)
                    {
                        DeleteOpmlFile();
                        return(Json(response));
                    }

                    Logger.LogError($"Edit category failed: {response.Message}");
                    ModelState.AddModelError("", response.Message);
                    return(Conflict(ModelState));
                }

                return(BadRequest());
            }
            catch (Exception e)
            {
                Logger.LogError(e, "Error Create Category.");

                ModelState.AddModelError("", e.Message);
                return(ServerError());
            }
        }
예제 #25
0
 public CreateCategoryCommand(EditCategoryRequest payload)
 {
     Payload = payload;
 }
예제 #26
0
        public async Task <IActionResult> Create(EditCategoryRequest model)
        {
            await _catService.CreateAsync(model.DisplayName, model.RouteName, model.Note);

            return(Created(string.Empty, model));
        }
예제 #27
0
        public async Task <IActionResult> Update(EditCategoryRequest request)
        {
            var result = await _categoryService.EditCategoryAsync(request);

            return(Ok(result));
        }
예제 #28
0
        public async Task <IActionResult> EditCategory([FromRoute(Name = "category_id")] Guid categoryId, [FromBody] EditCategoryRequest request)
        {
            // validate input
            if (!ModelState.IsValid)
            {
                return(HttpResult.BadRequest(ModelState));
            }

            // locate category
            var foundCategory = await _bagsContext.TagCategories
                                .Where(category => category.Id == categoryId)
                                .SingleOrDefaultAsync();

            if (foundCategory == null)
            {
                return(HttpResult.NotFound());
            }

            // verify there are actual changes
            if (foundCategory.Name == request.Name)
            {
                return(HttpResult.Ok(foundCategory.ToBaseWireFormat()));
            }

            // verify no conflicts with unique constraint
            var duplicateCategory = await _bagsContext.TagCategories
                                    .Where(category => category.Name == request.Name)
                                    .SingleOrDefaultAsync();

            if (duplicateCategory != null)
            {
                return(HttpResult.Conflict(duplicateCategory.ToBaseWireFormat()));
            }

            // change the name
            foundCategory.Name = request.Name;
            await _bagsContext.SaveChangesAsync();

            return(HttpResult.Ok(foundCategory.ToBaseWireFormat()));
        }
예제 #29
0
    public async Task <IActionResult> Create(EditCategoryRequest model)
    {
        await _mediator.Send(new CreateCategoryCommand(model));

        return(Created(string.Empty, model));
    }
예제 #30
0
 public UpdateCategoryCommand(Guid id, EditCategoryRequest payload)
 {
     Id      = id;
     Payload = payload;
 }