public async Task <IActionResult> UpdateSource(int id, [FromBody] UpdateCategoryDTO source) { try { if (source == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest("Invalid model object")); } var sourceEntity = await _repositoryWrapper.CategoryRepo.GetDataByIdAsync(id); if (sourceEntity == null) { return(NotFound()); } _mapper.Map(source, sourceEntity); _repositoryWrapper.CategoryRepo.UpdateData(sourceEntity); await _repositoryWrapper.SaveAsync(); return(Ok("Update successfully!")); } catch (Exception ex) { //_logger.LogError($"Something went wrong inside CreateSources action: {ex.Message}"); if (ex.InnerException != null) { return(BadRequest(ex.Message + "," + ex.InnerException.Message)); } return(BadRequest(ex.Message)); } }
public void UpdateCategory(UpdateCategoryDTO categoryDTO) { Category category = new Category() { id = categoryDTO.id, name = categoryDTO.name, displayname = categoryDTO.displayname }; _categoryRepository.Update(category); }
public async Task <CategoryDTO> Update(UpdateCategoryDTO dto) // update dto { if (dto == null) { return(null); } var entity = CategoryConverter.Convert(dto); entity = await unitOfWork.Repository <Category>().Update(entity); return(CategoryConverter.Convert(entity)); }
public async Task <IActionResult> Update(UpdateCategoryDTO dto) { var categoryDto = await service.Update(dto); if (categoryDto != null) { return(Ok()); } else { return(BadRequest($"{nameof(categoryDto)} is null")); } }
public ActionResult Edit([Bind(Include = "id,name,displayname")] UpdateCategoryDTO category) { if (ModelState.IsValid) { _categoryRepository.UpdateCategory(category); //_categoryRepository.Save(category); return(RedirectToAction("Index")); } else { return(View(category)); } }
public static Category Convert(UpdateCategoryDTO category) { if (category == null) { throw new ArgumentNullException(nameof(category)); } return(new Category { Id = category.Id, Title = category.Title, ParentCategoryId = category.ParentCategoryId, IsDeleted = false }); }
public async Task <IActionResult> PutCategory(int id, UpdateCategoryDTO category) { if (id != category.Id) { return(BadRequest()); } if (await _categoryRepository.UpdateAsync(BaseEntity.CreateFrom <Category>(category))) { await _categoryRepository.SaveAsync(); return(Ok()); } return(BadRequest()); }
public async Task <ExecuteResult> UpdateCategory(UpdateCategoryDTO category) { List <StoredProcedure> storedProcedures = new List <StoredProcedure>(); storedProcedures.Add( DbUtil.StoredProcedureBuilder.WithSPName("mscategory_update") .AddParam(category.Id) .AddParam(category.Name) .AddParam(category.AuditedUserId) .SP() ); IEnumerable <ExecuteResultDTO> executeResults = await ExecSPWithTransaction <ExecuteResultDTO>(storedProcedures.ToArray()); return(executeResults.Select(x => new ExecuteResult { InstanceId = x.InstanceId, }).FirstOrDefault()); }