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); }
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"; }
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()); }
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)); }
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()); }
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)); }
public abstract Task <GovDeliveryResponseModel <UpdateCategoryResponseModel> > UpdateCategoryAsync(UpdateCategoryRequestModel requestModel);
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) }); }
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) }); }