コード例 #1
0
        public async Task <Category> UpdateCategoryAsync(long id, UpdateCategoryRequestModel request)
        {
            var category = await FindAsync(id);

            if (category == null)
            {
                return(null);
            }

            if (request.Name != null)
            {
                category.Name = request.Name;
            }

            if (request.Description != null)
            {
                category.Description = request.Description;
            }


            _context.Categories.Update(category);
            if (await _context.SaveChangesAsync() > 0)
            {
                return(category);
            }

            return(null);
        }
コード例 #2
0
        public async void TestUpdateCategoryAsync(UpdateCategoryRequestModel requestModel)
        {
            var responseModel = await service.UpdateCategoryAsync(requestModel);

            Assert.Equal(HttpStatusCode.OK, responseModel.HttpResponse.StatusCode);
            Assert.NotNull(responseModel.Data);

            var categoryCode        = responseModel.Data.ToParam;
            var expectedCategoryUri = $"/api/account/{ACCOUNT_CODE}/categories/{categoryCode}.xml";
        }
コード例 #3
0
        public async Task <IActionResult> UpdateCategory(long id, [FromForm] UpdateCategoryRequestModel request)
        {
            var category = await _categoryRepository.UpdateCategoryAsync(id, request);

            if (category != null)
            {
                return(Ok(category));
            }

            return(BadRequest());
        }
コード例 #4
0
        public async Task <ActionResult> Update(string categoryId, UpdateCategoryRequestModel model)
        {
            var userId = this.User.GetId();
            var result = await this.categoryService.UpdateCategoryAsync(model.NewName, categoryId, userId);

            if (!result.Success)
            {
                return(Unauthorized(result.Errors));
            }

            return(this.Ok(result.Result));
        }
コード例 #5
0
        public async Task <ActionResult> Update(UpdateCategoryRequestModel model)
        {
            var userId = this.User.GetId();

            var updated = await this.categoryService.Update(model.Id, model.CategoryPicUrl, model.Name, userId);

            if (!updated)
            {
                return(BadRequest());
            }

            return(Ok());
        }
コード例 #6
0
        public IHttpActionResult Update(int id, UpdateCategoryRequestModel category)
        {
            if (id <= 0)
            {
                return(this.BadRequest(ErrorMessages.INVALID_ID));
            }

            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var categoryToUpdate = Mapper.Map <Category>(category);
            var updatedCategory  = this.categoriesServices.UpdateCategory(id, categoryToUpdate);

            if (updatedCategory == null)
            {
                return(this.NotFound());
            }

            return(this.Ok(updatedCategory.Id));
        }
コード例 #7
0
 public abstract Task <GovDeliveryResponseModel <UpdateCategoryResponseModel> > UpdateCategoryAsync(UpdateCategoryRequestModel requestModel);
コード例 #8
0
        public override async Task <GovDeliveryResponseModel <UpdateCategoryResponseModel> > UpdateCategoryAsync(UpdateCategoryRequestModel requestModel)
        {
            var responseModel = new UpdateCategoryResponseModel
            {
            };

            var httpResponse = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = SerializationUtils.ModelToStringContent(responseModel)
            };

            return(new GovDeliveryResponseModel <UpdateCategoryResponseModel>
            {
                HttpResponse = httpResponse,
                Data = await SerializationUtils.ResponseContentToModel <UpdateCategoryResponseModel>(httpResponse.Content)
            });
        }
コード例 #9
0
        public override async Task <GovDeliveryResponseModel <UpdateCategoryResponseModel> > UpdateCategoryAsync(UpdateCategoryRequestModel requestModel)
        {
            var res = await client.PutAsync($"categories/{requestModel.Code}.xml", SerializationUtils.ModelToStringContent(requestModel));

            InterceptHttpError(res);

            return(new GovDeliveryResponseModel <UpdateCategoryResponseModel>
            {
                HttpResponse = res,
                Data = await SerializationUtils.ResponseContentToModel <UpdateCategoryResponseModel>(res.Content)
            });
        }