public int CreateEntity(Category categoryToCreate) { using (var cmd = UnitOfWork.CreateCommand()) { try { cmd.CommandText = "CreateCategory"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@CategoryName", SqlDbType.VarChar, 50) { Value = categoryToCreate.CategoryName }); cmd.Parameters.Add(new SqlParameter("@BlogId", SqlDbType.Int) { Value = categoryToCreate.RelatedTo.Id }); var outPutParameter = new SqlParameter("@CreatedCategoryId", SqlDbType.Int, 50, ParameterDirection.InputOutput, false, 0, 0, "@CreatedCategoryId", DataRowVersion.Original, null); outPutParameter.Value = ParameterDirection.InputOutput; cmd.Parameters.Add(outPutParameter); cmd.ExecuteNonQuery(); int createdCategoryId = Convert.ToInt32(outPutParameter.Value); _categoryBuilder.SetCategoryId(categoryToCreate, createdCategoryId); return(createdCategoryId); } catch (SqlException ex) { throw new ApplicationException(ex.Message, ex); } } }
public AnswerStatus UpdateCategory(CategoryDto categoryDTO) { using (var uow = _unitOfWorkFactory.Create()) { try { var categoryToUpdate = _categoryBuilder.CreateCategory(categoryDTO.CategoryName); _categoryBuilder.SetCategoryId(categoryToUpdate, categoryDTO.Id); var categoryRepository = _repositoryFactory.CreateCategoryRepository(uow); categoryRepository.UpdateEntity(categoryToUpdate); uow.SaveChanges(); return(AnswerStatus.Successfull); } catch (Exception exc) { _logger.Log(exc.ToString()); return(AnswerStatus.Failed); } } }