public CategoryUpdateResponse Update(CategoryUpdateRequest request) { var response = new CategoryUpdateResponse(); var existing = CheckForExisting(request.Name); if (existing != null && existing.Id != request.Id) { response.ErrorMessage = "Update would create a duplicate"; } else { var existingById = _categoryRepository.Get(request.Id); if (existingById == null) { response.ErrorMessage = "Category not found"; } else { _session.Flush(); existingById.Name = request.Name; existingById.LastUpdate = DateTime.UtcNow; _categoryRepository.Update(existingById); response.Category = new Category() { Id = existingById.Id, Name = existingById.Name, LastUpdate = existingById.LastUpdate }; } } return(response); }
public CategoryUpdateResponse Update([FromBody] CategoryUpdateRequest request) { CategoryUpdateResponse response = new CategoryUpdateResponse(); if (request.Id == 0 || request.Id < 0) { response.Status = -1; return(response); } CategoryEntity entity = categoryRepository.GetById(request.Id); if (entity == null) { response.Status = 404; return(response); } categoryRepository.Update(categoryConvertor.toEntity(request, entity)); theCategoryMeta.Refresh(); response.Status = 1; return(response); }